{"id":36917,"date":"2026-01-23T19:04:41","date_gmt":"2026-01-23T13:34:41","guid":{"rendered":"https:\/\/codeforgeek.com\/?p=36917"},"modified":"2026-04-15T23:32:50","modified_gmt":"2026-04-15T18:02:50","slug":"git-commands","status":"publish","type":"post","link":"https:\/\/codeforgeek.com\/git-commands\/","title":{"rendered":"All Git Commands Explained with Examples (Git Cheat Sheet 2026)"},"content":{"rendered":"\n<p>As developers, <strong>we run Git commands every day<\/strong>, for pushing code to GitHub, pulling changes from a remote repository, etc directly from our system command line.<\/p>\n\n\n\n<p>No doubt Git and GitHub are amazing, but the <strong>real problem is remembering all those Git commands and their flags<\/strong>. Although general commands are simple, like <code>git add<\/code>, <code>git push<\/code>, etc, when we need something specific, we need to Google it.<\/p>\n\n\n\n<p>But what if, instead of memorising Git commands, <strong>you actually understood the meaning behind each of them, the purpose of its flags, and when to use them? <\/strong>That\u2019s exactly what this guide is for.<\/p>\n\n\n\n<p>In this complete Git cheat sheet, I will<strong><em> explain all Git commands with real examples<\/em><\/strong>, so you <strong><em>don\u2019t just copy-paste them<\/em><\/strong>, but <strong><em>truly understand how Git works<\/em><\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Essential Git Commands for Configuration<\/h2>\n\n\n\n<p>We start by setting up our environment. These commands help us configure Git to work correctly for our specific needs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git config<\/h3>\n\n\n\n<p>This command sets configuration values for your user name and email. We use it to tell Git who is making the changes. It ensures that commits are attributed to the correct person. It can be set globally or for a single project.<\/p>\n\n\n\n<p>Example: <code>git config --global user.name \"Your Name\"<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git help<\/h3>\n\n\n\n<p>This command displays the help pages for other Git commands. We use it when we forget the options or flags for a specific tool. It opens a detailed manual in our terminal or browser.<\/p>\n\n\n\n<p>Example: <code>git help commit<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Git Commands for Starting Projects<\/h2>\n\n\n\n<p>These Git commands are the first steps we take when creating a new version controlled project.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git init<\/h3>\n\n\n\n<p>This command initializes a new empty Git repository. We use it to start tracking a project folder. It creates a hidden subdirectory that stores all the version history metadata.<\/p>\n\n\n\n<p>Example: <code>git init<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git clone<\/h3>\n\n\n\n<p>This command copies an existing repository from a remote location to our local machine. We use it to download a project so we can work on it. It saves a full copy of the history on our computer.<\/p>\n\n\n\n<p>Example: <code>git clone https:\/\/github.com\/user\/project.git<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Git Commands for Saving Changes<\/h2>\n\n\n\n<p>Once we start working, we need to save our progress. These Git commands let us stage and save our snapshots.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git status<\/h3>\n\n\n\n<p>This command shows the state of the working directory. We use it to see which files have changed or are ready to be committed. It lists untracked, modified, and staged files.<\/p>\n\n\n\n<p>Example: <code>git status<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git add<\/h3>\n\n\n\n<p>This command moves files from the working directory to the staging area. We use it to select specific changes to include in our next snapshot. It prepares content for the commit.<\/p>\n\n\n\n<p>Example: <code>git add filename.txt<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git commit<\/h3>\n\n\n\n<p>This command saves the staged changes to the local repository history. We use it to create a permanent record of our project at a specific point in time. We usually include a message to describe the update.<\/p>\n\n\n\n<p>Example: <code>git commit -m \"Fixed login bug\"<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Git Commands for Viewing History<\/h2>\n\n\n\n<p>We often need to look back at what happened. These Git commands help us explore the timeline of our project.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git log<\/h3>\n\n\n\n<p>This command displays a list of previous commits in reverse order. We use it to see the history of changes, authors, and dates. It helps us understand how the project evolved.<\/p>\n\n\n\n<p>Example: <code>git log<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git show<\/h3>\n\n\n\n<p>This command shows detailed information about a specific commit. We use it to view the changes made in that snapshot. It displays the commit metadata and the file diffs.<\/p>\n\n\n\n<p>Example: <code>git show abc1234<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git diff<\/h3>\n\n\n\n<p>This command shows differences between various states of the project. We use it to see exactly what lines changed in a file. It compares the working directory with the staging area or commits.<\/p>\n\n\n\n<p>Example: <code>git diff<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Git Commands for Branching and Merging<\/h2>\n\n\n\n<p>Branching allows us to work on different tasks separately. These Git commands manage our workflow structure.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git branch<\/h3>\n\n\n\n<p>This command lists, creates, or deletes branches. We use it to organize our work into separate lines of development. It lets us isolate features from the main codebase.<\/p>\n\n\n\n<p>Example: <code>git branch feature-x<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git checkout<\/h3>\n\n\n\n<p>This command switches between branches or restores files. We use it to move our working directory to a different branch. It updates the files in our folder to match the chosen branch.<\/p>\n\n\n\n<p>Example: <code>git checkout main<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git switch<\/h3>\n\n\n\n<p>This command is a newer way to switch branches. We use it to move to another branch more clearly than checkout. It is designed specifically for changing our view of the tree.<\/p>\n\n\n\n<p>Example: <code>git switch dev<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git merge<\/h3>\n\n\n\n<p>This command combines the history of two branches together. We use it to bring changes from one branch into another. It integrates our feature work back into the main line.<\/p>\n\n\n\n<p>Example: <code>git merge feature-x<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Git Commands for Remote Repositories<\/h2>\n\n\n\n<p>Collaboration requires connecting with servers. These Git commands handle the interaction with remote hosting services.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git remote<\/h3>\n\n\n\n<p>This command manages the set of remote repositories tracked. We use it to view, add, or remove connections to servers. It links our local project to the cloud.<\/p>\n\n\n\n<p>Example: <code>git remote add origin https:\/\/github.com\/user\/repo.git<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git fetch<\/h3>\n\n\n\n<p>This command downloads data from remote repositories to our local machine. We use it to see what others have committed without changing our files. It updates our remote tracking references.<\/p>\n\n\n\n<p>Example: <code>git fetch origin<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git pull<\/h3>\n\n\n\n<p>This command fetches data and immediately merges it into our current branch. We use it to update our local copy with the latest changes from the server. It combines fetch and merge in one step.<\/p>\n\n\n\n<p>Example: <code>git pull origin main<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git push<\/h3>\n\n\n\n<p>This command uploads our local commits to a remote repository. We use it to share our work with the rest of the team. It sends our changes to the server for storage.<\/p>\n\n\n\n<p>Example: <code>git push origin main<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Git Commands for Undoing Changes<\/h2>\n\n\n\n<p>Mistakes happen often in development. These Git commands help us fix errors safely.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git reset<\/h3>\n\n\n\n<p>This command resets the current branch to a specific state. We use it to unstage files or move the branch pointer. It can change the history if used improperly.<\/p>\n\n\n\n<p>Example: <code>git reset HEAD~1<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git revert<\/h3>\n\n\n\n<p>This command creates a new commit that undoes a previous change. We use it to safely remove a bug without deleting history. It keeps the timeline linear and intact.<\/p>\n\n\n\n<p>Example: <code>git revert abc1234<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git restore<\/h3>\n\n\n\n<p>This command discards changes in the working directory. We use it to undo local edits to a file. It resets the file to match the staged commit or HEAD.<\/p>\n\n\n\n<p>Example: <code>git restore file.txt<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Advanced Git Commands for Maintenance<\/h2>\n\n\n\n<p>For complex workflows, we use these powerful tools to keep our repository clean.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git stash<\/h3>\n\n\n\n<p>This command temporarily saves changes that are not ready to commit. We use it when we need to switch context quickly but want to keep our work. It stores the modifications safely on a stack.<\/p>\n\n\n\n<p>Example: <code>git stash<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git clean<\/h3>\n\n\n\n<p>This command removes untracked files from the working directory. We use it to delete clutter and build artifacts. It cleans up the folder to match the repository state.<\/p>\n\n\n\n<p>Example: <code>git clean -f<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git rebase<\/h3>\n\n\n\n<p>This command reapplies commits on top of another base tip. We use it to maintain a linear and clean history. It moves our branch to start at the newest point of the main branch.<\/p>\n\n\n\n<p>Example: <code>git rebase main<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git cherry-pick<\/h3>\n\n\n\n<p>This command applies a specific commit from one branch to another. We use it to bring a single fix to our current branch without merging everything. It is useful for backports.<\/p>\n\n\n\n<p>Example: <code>git cherry-pick abc1234<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">git reflog<\/h3>\n\n\n\n<p>This command shows a log of where our HEAD pointer has been. We use it to recover lost commits or find mistakes. It acts as a safety net for almost any action.<\/p>\n\n\n\n<p>Example: <code>git reflog<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Git commands give us full control over code versioning and collaboration. By understanding how each command works, we can handle everyday coding tasks and complex workflows with ease. This Git cheatsheet is meant to be both a learning guide and a quick reference. <\/p>\n\n\n\n<p>To further improve your workflow, check out:<br><a href=\"https:\/\/codeforgeek.com\/using-github-copilot-in-vs-code\/\">A Guide to Using GitHub Copilot in VS Code (With Video)<\/a><\/p>\n\n\n\n<p>You can also check out the official Git cheatsheet, take a screenshot, and save it on your phone for quick reference:<br><a href=\"https:\/\/git-scm.com\/cheat-sheet\" target=\"_blank\" rel=\"noopener\">Git Cheat Sheet<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As developers, we run Git commands every day, for pushing code to GitHub, pulling changes from a remote repository, etc directly from our system command line. No doubt Git and GitHub are amazing, but the real problem is remembering all those Git commands and their flags. Although general commands are simple, like git add, git [&hellip;]<\/p>\n","protected":false},"author":79,"featured_media":36926,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_surecart_dashboard_logo_width":"180px","_surecart_dashboard_show_logo":true,"_surecart_dashboard_navigation_orders":true,"_surecart_dashboard_navigation_invoices":true,"_surecart_dashboard_navigation_subscriptions":true,"_surecart_dashboard_navigation_downloads":true,"_surecart_dashboard_navigation_billing":true,"_surecart_dashboard_navigation_account":true,"_uag_custom_page_level_css":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-36917","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorial"],"blocksy_meta":[],"uagb_featured_image_src":{"full":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2026\/01\/ALl-GIT-Commands-Explained.png",1920,1080,false],"thumbnail":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2026\/01\/ALl-GIT-Commands-Explained-150x150.png",150,150,true],"medium":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2026\/01\/ALl-GIT-Commands-Explained-300x169.png",300,169,true],"medium_large":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2026\/01\/ALl-GIT-Commands-Explained-768x432.png",768,432,true],"large":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2026\/01\/ALl-GIT-Commands-Explained-1024x576.png",1024,576,true],"1536x1536":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2026\/01\/ALl-GIT-Commands-Explained-1536x864.png",1536,864,true],"2048x2048":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2026\/01\/ALl-GIT-Commands-Explained.png",1920,1080,false]},"uagb_author_info":{"display_name":"Aditya Gupta","author_link":"https:\/\/codeforgeek.com\/author\/aditya\/"},"uagb_comment_info":0,"uagb_excerpt":"As developers, we run Git commands every day, for pushing code to GitHub, pulling changes from a remote repository, etc directly from our system command line. No doubt Git and GitHub are amazing, but the real problem is remembering all those Git commands and their flags. Although general commands are simple, like git add, git&hellip;","_links":{"self":[{"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/posts\/36917","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/users\/79"}],"replies":[{"embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/comments?post=36917"}],"version-history":[{"count":0,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/posts\/36917\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/media\/36926"}],"wp:attachment":[{"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/media?parent=36917"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/categories?post=36917"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/tags?post=36917"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}