Git Cheatsheet
Here is a reference for many useful git commands.
If you can get to the point where you don't need to look up the bare essential commands, then you are in a good place.
Bare Essentials
Command | Description |
---|---|
git clone <repo-link |
clone a repository from Github |
git checkout <branch-name> |
checkout to branch that already exists |
git branch |
list all branches + identify current branch |
git branch <new-branch-name> |
create a new branch |
git pull |
pull changes from remote |
git push |
push changes to remoate |
git status |
show status of local repository |
git add <file_1> <file_2> ... <file_n> |
add specific files to staging area |
git commit |
commit changes to local repository |
git init |
create local repository with root in curent directory |
Syntactic Sugar for Essentials
Command | Description |
---|---|
git add -A |
add all changes to staging area |
git commit -m "<commit-title>" |
commit changes to local repository with commit title |
git commit -m "<commit-title>" -m "<commit-description>" |
commit changes to local repository with commit title and description |
git checkout -b <new-branch-name> |
create a new branch and checkout to it |
Good to Know
Command | Description |
---|---|
git restore <file_1> <file_2> ... <file_n> |
undo changes to files not on the staging area |
git restore --staged <file_1> <file_2> ... <file_n> |
remove files from staging area |
git log |
show commit history |
git diff |
show changes between commits |
git stash |
save changes to a stash (stack) |
git stash pop |
pop and apply changes from top of stash |
git stash apply |
apply changes from top of stash |
git help |
show help menu |
Advanced
Command | Description |
---|---|
git rebase -i |
rebase local repository in interactive mode |
git merge <other-branch> |
merge other branch into current branch |
You need to run these once
Command | Description |
---|---|
git config --global user.name "<name>" |
set name for local repository |
git config --global user.email "<email>" |
set email for local repository |
Just Google it
Command | Description |
---|---|
git config --global alias.<alias-name> <command> |
create alias for git command |
Git Will Tell You if You Need to Run This
Command | Description |
---|---|
git push --set-upstream origin <branch-name> |
push changes to remote and set remote branch as upstream |