Git Cheat Sheet
Category | Command | Description |
---|---|---|
Setup | git 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 init | Initialize a new git repository in the current directory. | |
git clone [url] | Clone a repository into a new directory. | |
Stage & Snapshot | git status | Show 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 diff | Show diff of what is changed but not staged. | |
git diff --staged | Diff of what is staged but not yet committed. | |
git commit -m "[message]" | Commit your staged content as a new commit snapshot. | |
Branch & Merge | git branch | List 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 log | Show all commits in the current branch’s history. | |
Share & Update | git 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 pull | Fetch and merge any commits from the tracking remote branch. | |
Inspect & Compare | git 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
Post a Comment