Skip to main content

Git Cheat Sheet

 

Git Cheat Sheet




CategoryCommandDescription
Setupgit config --global user.name "[name]"Set a name that will be attached to your commits and tags.
git config --global user.email "[email]"Set an email that will be attached to your commits and tags.
git initInitialize a new git repository in the current directory.
git clone [url]Clone a repository into a new directory.
Stage & Snapshotgit statusShow modified files in the working directory, staged for your next commit.
git add [file]Add a file as it looks now to your next commit (stage).
git reset [file]Unstage a file while retaining the changes in the working directory.
git diffShow diff of what is changed but not staged.
git diff --stagedDiff of what is staged but not yet committed.
git commit -m "[message]"Commit your staged content as a new commit snapshot.
Branch & Mergegit branchList all of the branches in your repo.
git branch [name]Create a new branch at the current commit.
git checkout [branch]Switch to another branch and check it out into your working directory.
git merge [branch]Merge the specified branch’s history into the current one.
git logShow all commits in the current branch’s history.
Share & Updategit remote add [alias] [url]Add a git URL as an alias.
git fetch [alias]Fetch down all the branches from that Git remote.
git merge [alias]/[branch]Merge a remote branch into your current branch to bring it up to date.
git push [alias] [branch]Transmit local branch commits to the remote repository branch.
git pullFetch and merge any commits from the tracking remote branch.
Inspect & Comparegit log --follow [file]Show the commits that changed file, even across renames.
git diff [branchB]...[branchA]Show the diff of what is in branchA that is not in branchB.
git show [SHA]Show any object in Git in human-readable format.

This table summarizes the most frequently used Git commands, providing a quick reference to manage your projects efficiently. Whether you're new to Git or need a quick refresher, this cheat sheet is a valuable tool for your development workflow.

Comments

  1. I like how clean and structured this guide is—it’s perfect for beginners who get overwhelmed with Git commands. Personally, git reset and git checkout were confusing until I started using a reference like this alongside my GitHub workflow. Would love to see another post covering common Git mistakes and how to fix them.

    ReplyDelete

Post a Comment