git --version | Get the version of git. | |
git init <directory> | Create empty git repo in specified directory. | |
git config user.name <name> | Define author name to be used for all commits. | |
git config user.email <email> | Define author email to be used for all commits. | |
git clone <repo> | Clone repo located at <repo> onto local machine. | |
git status | List which files are staged, unstaged and untracked. | |
git add . | Get everything ready to commit. | |
git add index.html | Get specific file ready to commit. | |
git commit -m "message" | Commit the staged snapshot. | |
git log | Display the entire commit history. | |
git diff | Show all local file changes in the working tree. | |
git push origin <branch> | Push the <branch> to the remote repo. |
git branch | List all branches in your repo. | |
git checkout -b <branch> | Create and checkout a new branch named <branch> | |
git branch -a | List remote and local branches. | |
git checkout <branch> | Checkout to an existing <branch> | |
git push origin <branch> | Push the <branch> to the remote repo. | |
git branch -m <newname> | Rename the current branch. | |
git branch -d <branch> | Delete a local <branch> | |
git merge <branch> | Merge <branch> into the current branch. | |
git merge --abort | Abort the merge, in case of conflicts. | |
git cherry-pick 76ce3e6 | Merge a specific commit. | |
git push origin :<branch> | Delete a remote <branch> |
git log | Show commits. | |
git log --oneline | Show one line summary of commits. | |
git log -3 | Show commit history of last three commits. | |
git log -p | Show changes. | |
git log --graph | Show history of commits as graph. | |
git log --stat --summary | Show stats and summary of commits. | |
git reflog | Show a log of changes to the local repo's HEAD. |
git stash list | Show all stashes. | |
git stash save "stash name" && git stash | Save a change to stash. | |
git stash branch <branch_name> | Create branch from stash. | |
git stash pop | Apply a stash. | |
git stash clear | Deletes complete stash. |
git reset HEAD <file> | Remove <file> from staging area. | |
git reset | Reset staging area to match the recent commit. | |
git reset --hard | Reset staging area, working dir and overwrites all changes. | |
git clean -df | Delete untracked files and directories. | |
git clean -f | Delete untracked files. |
git diff | Compare modified files. | |
git diff --staged | Compare modified files within the staging area. | |
git diff <branch>..<branch> | Compare two branches. | |
git diff 76ce3e6..e251d8d | Compare two specific commits. |