| Command | What it does | Common Flag/Example |
|---|---|---|
git config --global user.name "Your Name" | Sets the name you want to be associated with your commits | --global sets the config for your user account |
git config --global user.email "you@example.com" | Sets the email you want to be associated with your commits | --global sets the config for your user account |
git config --global core.editor "vim" | Sets the default text editor for Git | --global sets the config for your user account |
git init | Initializes a new Git repository | |
git clone <repository> | Clones an existing repository | |
git remote add origin <url> | Adds a remote repository | |
git remote -v | Shows all remote repositories | |
git config --list | Lists all Git configuration settings | |
git config --global core.autocrlf true | Configures line endings for Windows | --global sets the config for your user account |
git config --global core.autocrlf false | Configures line endings for Unix/Linux | --global sets the config for your user account |
| Command | What it does | Common Flag/Example |
|---|---|---|
git add <file> | Adds a file to the staging area | |
git add . | Adds all changes to the staging area | |
git add -A | Adds all changes including deletions | |
git commit -m "message" | Commits staged changes with a message | -m allows you to type a commit message directly |
git commit -a -m "message" | Commits all tracked files with a message | -a stages all tracked files |
git commit --amend | Amends the most recent commit | |
git status | Shows the status of the working directory and staging area | |
git diff | Shows differences between working directory and staging area | |
git diff --cached | Shows differences between staging area and last commit | |
git diff HEAD~1 | Shows differences between current and previous commit |
| Command | What it does | Common Flag/Example |
|---|---|---|
git branch | Lists all branches in the repository | |
git branch -a | Lists all local and remote branches | |
git branch <new-branch> | Creates a new branch | |
git branch -m <old-name> <new-name> | Renames a branch | |
git checkout <branch> | Switches to the specified branch | |
git checkout -b <new-branch> | Creates and switches to a new branch | |
git merge <branch> | Merges the specified branch into the current branch | |
git merge --no-ff <branch> | Merges without fast-forwarding | |
git merge --squash <branch> | Squashes commits into one | |
git branch -d <branch> | Deletes a merged branch | |
git branch -D <branch> | Deletes a branch regardless of its merge status |
| Command | What it does | Common Flag/Example |
|---|---|---|
git fetch <remote> | Downloads objects and refs from another repository | |
git fetch --all | Fetches all remotes | |
git pull <remote> <branch> | Fetches and merges a remote branch into the current branch | |
git pull --rebase | Fetches and rebases instead of merging | |
git push <remote> <branch> | Updates the remote branch with your local changes | |
git push --set-upstream origin <branch> | Sets upstream for the current branch | |
git push --force-with-lease | Force pushes with safety | |
git push --tags | Pushes all tags to the remote | |
git push origin --delete <branch> | Deletes a remote branch | |
git remote update origin | Updates remote references |
| Command | What it does | Common Flag/Example |
|---|---|---|
git log | Shows commit logs | |
git log --oneline | Shows commit logs in a compact format | |
git log --graph | Shows commit logs with a graph | |
git log --oneline --graph --all | Shows all branches with a graph | |
git log --author="John Doe" | Shows commits by a specific author | |
git log --since="2023-01-01" | Shows commits since a specific date | |
git show <commit> | Shows detailed information about a commit | |
git show --name-only <commit> | Shows only file names changed in a commit | |
git blame <file> | Shows line-by-line commit information for a file | |
git reflog | Shows reference logs |
| Command | What it does | Common Flag/Example |
|---|---|---|
git reset --hard HEAD~1 | Resets the current branch to the previous commit | --hard resets working directory and index |
git reset --soft HEAD~1 | Resets the current branch but keeps changes staged | --soft keeps changes in staging area |
git reset HEAD <file> | Unstages a file from the staging area | |
git revert <commit> | Reverts the specified commit | |
git revert --no-commit <commit> | Reverts without committing | |
git restore <file> | Restores working directory files | |
git restore --staged <file> | Unstages a file from the staging area | |
git checkout -- <file> | Discards changes in the working directory | |
git checkout HEAD -- <file> | Restores a file to its state in the last commit | |
git clean -fd | Removes untracked files and directories | -f forces removal, -d removes directories |
| Command | What it does | Common Flag/Example |
|---|---|---|
git stash | Stashes the changes in a dirty working directory away | |
git stash save "message" | Stashes changes with a message | |
git stash list | Lists the stash entries | |
git stash show | Shows the changes in the stash | |
git stash show -p | Shows the changes in the stash in patch format | |
git stash pop | Applies the most recent stashed changes and removes them from the stash list | |
git stash apply | Applies the most recent stashed changes without removing them | |
git stash apply stash@{n} | Applies a specific stash entry | |
git stash drop | Drops the most recent stash entry | |
git stash clear | Removes all stash entries |
| Command | What it does | Common Flag/Example |
|---|---|---|
git rebase <branch> | Applies commits of the current branch on top of another base tip | |
git rebase -i HEAD~3 | Interactive rebase of the last 3 commits | -i enables interactive mode |
git rebase --onto <new-base> <old-base> <branch> | Rebases a branch onto a new base | |
git rebase --abort | Aborts the current rebase operation | |
git cherry-pick <commit> | Applies the changes introduced by some existing commits | |
git cherry-pick -n <commit> | Cherry-picks without committing | |
git cherry-pick <commit1> <commit2> | Cherry-picks multiple commits | |
git commit --amend | Amends the most recent commit | |
git commit --amend --no-edit | Amends the most recent commit without changing the message | |
git rebase -i --autosquash | Interactive rebase with autosquash |
| Command | What it does | Common Flag/Example |
|---|---|---|
git tag <tagname> | Creates a tag with the specified name | |
git tag -a <tagname> -m "message" | Creates an annotated tag with a message | -a creates an annotated tag |
git tag -l | Lists all tags | |
git tag -l "v1.*" | Lists tags matching a pattern | |
git push origin <tagname> | Pushes a tag to the remote repository | |
git push origin --tags | Pushes all tags to the remote repository | |
git checkout <tagname> | Checks out a tag | |
git checkout -b <branchname> <tagname> | Creates a branch from a tag | |
git tag -d <tagname> | Deletes a tag | |
git tag -v <tagname> | Verifies a tag |