{"id":435,"date":"2026-02-03T16:26:36","date_gmt":"2026-02-03T16:26:36","guid":{"rendered":"https:\/\/www.webmobkey.com\/blog\/?p=435"},"modified":"2026-02-03T16:37:31","modified_gmt":"2026-02-03T16:37:31","slug":"basic-git-commands","status":"publish","type":"post","link":"https:\/\/www.webmobdesign.com\/blog\/en\/basic-git-commands\/","title":{"rendered":"Basic Git Commands"},"content":{"rendered":"\n<p>Git is one of the most widely used version control systems in modern software development. It allows developers to track changes, collaborate with teams, and manage project history efficiently. Whether you are a beginner or someone who wants to refresh their knowledge, understanding the basic Git commands is essential.<\/p>\n\n\n\n<p>In this article, we will go through the most commonly used Git commands with clear explanations and examples.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>1. Configuring Git User Information<\/strong><\/h2>\n\n\n\n<p>Before making commits, Git needs to know who you are. This information will appear in your commit history.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit config --global user.name &quot;Your Name&quot;\ngit config --global user.email &quot;your.email@example.com&quot;\n<\/pre><\/div>\n\n\n<p>To check your current configuration:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit config --list\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2. Navigating the Terminal<\/strong><\/h2>\n\n\n\n<p>Although not Git-specific, these commands are commonly used while working with Git.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npwd\n<\/pre><\/div>\n\n\n<p>Displays the current directory.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; title: ; notranslate\" title=\"\">\nls # Displays the current directory\n<\/pre><\/div>\n\n\n<p>Lists files and folders in the current directory.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nls -a\n<\/pre><\/div>\n\n\n<p>Lists all files, including hidden ones such as <code>.git<\/code>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>3. Initializing a Git Repository<\/strong><\/h2>\n\n\n\n<p>To start using Git in a project, navigate to your project folder and run:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit init\n<\/pre><\/div>\n\n\n<p>This command creates a hidden <code>.git<\/code> directory, which contains all the version control information for your project.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>4. Checking Repository Status<\/strong><\/h2>\n\n\n\n<p>To see the current state of your working directory:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit status\n<\/pre><\/div>\n\n\n<p>This command shows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Modified files<\/li>\n\n\n\n<li>Staged files<\/li>\n\n\n\n<li>Untracked files<\/li>\n<\/ul>\n\n\n\n<p>It is one of the most frequently used Git commands.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>5. Adding Files to the Staging Area<\/strong><\/h2>\n\n\n\n<p>To add a specific file:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit add index.html\n<\/pre><\/div>\n\n\n<p>To add all files:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit add .\n<\/pre><\/div>\n\n\n<p>The staging area allows you to choose which changes will be included in the next commit.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>6. Committing Changes<\/strong><\/h2>\n\n\n\n<p>Once files are staged, you can save them to the repository with a commit:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit commit -m &quot;Initial project setup&quot;\n<\/pre><\/div>\n\n\n<p>A commit message should be short, clear, and descriptive.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>7. Viewing Commit History<\/strong><\/h2>\n\n\n\n<p>To see the list of commits:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit log\n<\/pre><\/div>\n\n\n<p>For a compact view:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit log --oneline\n<\/pre><\/div>\n\n\n<p>This helps you understand the project\u2019s history and track changes over time.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>8. Viewing File Differences<\/strong><\/h2>\n\n\n\n<p>To see changes that are not staged yet:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit diff\n<\/pre><\/div>\n\n\n<p>To see changes that are staged:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit diff --staged\n<\/pre><\/div>\n\n\n<p>This command shows line-by-line differences between versions.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>9. Working with Branches<\/strong><\/h2>\n\n\n\n<p>Branches allow you to work on features independently without affecting the main codebase.<\/p>\n\n\n\n<p>List branches:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit branch\n<\/pre><\/div>\n\n\n<p>Create a new branch:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit branch feature-login\n<\/pre><\/div>\n\n\n<p>Switch to a branch:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit switch feature-login\n<\/pre><\/div>\n\n\n<p>Or using the older command:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit checkout feature-login\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>10. Merging Branches<\/strong><\/h2>\n\n\n\n<p>To merge a branch into the current branch:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit merge feature-login\n<\/pre><\/div>\n\n\n<p>This combines the changes from the selected branch into your active branch.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>11. Undoing Changes<\/strong><\/h2>\n\n\n\n<p>Restore a modified file:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit restore index.html\n<\/pre><\/div>\n\n\n<p>Remove a file from staging (but keep it locally):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit rm --cached index.html\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>12. Reverting a Commit<\/strong><\/h2>\n\n\n\n<p>To safely undo a commit without rewriting history:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit revert &amp;lt;commit-hash&gt;\n<\/pre><\/div>\n\n\n<p>This creates a new commit that reverses the changes.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>13. Resetting Commits<\/strong><\/h2>\n\n\n\n<p>Git reset allows you to undo commits in different ways:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit reset --soft HEAD~1\n<\/pre><\/div>\n\n\n<p>Keeps changes staged.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit reset --mixed HEAD~1\n<\/pre><\/div>\n\n\n<p>Keeps changes but unstages them.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ngit reset --hard HEAD~1\n<\/pre><\/div>\n\n\n<p>\u26a0\ufe0f Completely removes changes (use with caution).<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>14. Using <code>.gitignore<\/code><\/strong><\/h2>\n\n\n\n<p>To prevent certain files from being tracked:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ntouch .gitignore\n<\/pre><\/div>\n\n\n<p>Example <code>.gitignore<\/code> content:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnode_modules\/\n.env\n*.log\n<\/pre><\/div>\n\n\n<p>This is especially useful for ignoring sensitive files or dependencies.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>15. Removing Git from a Project<\/strong><\/h2>\n\n\n\n<p>To completely remove Git tracking:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nrm -rf .git\n<\/pre><\/div>\n\n\n<p>This deletes all Git history from the project.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>Git is an essential tool for every developer. By mastering these basic Git commands, you can manage your code efficiently, collaborate with others, and maintain a clean project history. As you grow more comfortable with Git, you can explore advanced features like rebasing, cherry-picking, and remote repositories.<\/p>\n\n\n\n<p>Happy coding \ud83d\ude80<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Git is one of the most widely used version control systems in modern software development. It &hellip; <a title=\"Basic Git Commands\" class=\"hm-read-more\" href=\"https:\/\/www.webmobdesign.com\/blog\/en\/basic-git-commands\/\"><span class=\"screen-reader-text\">Basic Git Commands<\/span>Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":437,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[91],"tags":[],"class_list":["post-435","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software"],"_links":{"self":[{"href":"https:\/\/www.webmobdesign.com\/blog\/wp-json\/wp\/v2\/posts\/435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webmobdesign.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webmobdesign.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webmobdesign.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webmobdesign.com\/blog\/wp-json\/wp\/v2\/comments?post=435"}],"version-history":[{"count":5,"href":"https:\/\/www.webmobdesign.com\/blog\/wp-json\/wp\/v2\/posts\/435\/revisions"}],"predecessor-version":[{"id":444,"href":"https:\/\/www.webmobdesign.com\/blog\/wp-json\/wp\/v2\/posts\/435\/revisions\/444"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webmobdesign.com\/blog\/wp-json\/wp\/v2\/media\/437"}],"wp:attachment":[{"href":"https:\/\/www.webmobdesign.com\/blog\/wp-json\/wp\/v2\/media?parent=435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webmobdesign.com\/blog\/wp-json\/wp\/v2\/categories?post=435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webmobdesign.com\/blog\/wp-json\/wp\/v2\/tags?post=435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}