git add . | Stage all file changes, ready for commit. |
git add -f | Stage all file changes including ignored files, ready for commit. |
git add --all | Stage all file changes, ready for commit. |
git add <directory> | Stage all changes in <directory> for the next commit. |
git add <file> | Stage <file> in its current state for the next commit. |
git branch | List all the branches in the local repository. |
git branch -a | List all the branches in the local and remote repository. |
git branch -d <branch> | Delete a branch named <branch> . |
git branch -m <branch> | Rename a branch named <branch> . |
git branch <branch> | Create a new branch named <branch> . |
git blame <file> | List the change dates and authors for <file> . |
git checkout <branch> | Switch to an existing branch named <branch> . |
git checkout <tag> | Switch to an existing tag named <tag> . |
git checkout -b <branch> | Create and switch to a new branch named <branch> . |
git checkout -- . | Undo local modifications to all files. |
git checkout -- <file> | Undo local modifications to <file> . |
git clean -df | Delete all untracked files and directories. |
git clean -f | Delete all untracked files. |
git clean -n | Shows which files would be removed from working directory. |
git clone <url> | Clone a remote repository into a newly created directory. |
git clone <url> <directory> | Clone a remote repository into a newly created directory and name the directory <directory> . |
git clone -l <path/to/repo> | Clone a local repository into a newly created directory. |
git clone -b <url> <name> | Clone a remote repository into a newly created directory and change the branch HEAD to <name> . |
git clone -o <url> <name> | Clone a remote repository into a newly created directory and name the remote <name> . |
git clone --no-tags <url> | Clone a remote repository into a newly created directory without any tags. |
git commit -am "<message> " | Commit all tracked files changes to versioned history, and use <message> as the commit message. |
git commit -m "<message> " | Commit all staged files changes to versioned history, and use <message> as the commit message. |
git commit --amend | Replace the last commit with the staged changes and last commit combined. Use with nothing staged to edit the last commit’s message. |
git config user.name <name> | Define author name to be used for all commits in current repo. Devs commonly use --global flag to set config options for current user. |
git config --global alias. <alias-name> <git-command> | Create shortcut for a Git command. E.g. alias.glog log --graph --oneline will set git glog equivalent to git log --graph --oneline. |
git config --global color.ui auto | Enable helpful colorization of command line output. |
git config --global user.email <email> | Define the author email to be used for all commits by the current user. |
git config --global user.name <name> | Define the author name to be used for all commits by the current user. |
git config --global --edit | Open the global configuration file in a text editor for manual editing. |
git config --system core.editor <editor> | Set text <editor> to be used by commands for all users on the machine (e.g., vi). |
git diff | Show the file changes that are unstaged. |
git diff HEAD | Show the difference between staged and unstaged file changes. |
git diff --cached | Show the difference between file changes that are staged and the last commit. |
git diff --staged | Show the difference between file changes that are staged, but not yet committed. |
git diff <branch1> <branch2> | Show the difference between <branch1> and <branch2> file changes. |
git diff <commit1> <commit2> | Show the difference between <commit1> and <commit2> file changes. |
git fetch <name> | Fetch file changes of all the branches from the <name> repository. |
git fetch <name> <branch> | Fetch file changes of a specific <branch> from the <name> repository. |
git fetch --prune <name> | Remove remote references that were removed from the <name> repository. |
git init | Initialize an existing directory as a Git repository. |
git init <directory> | Create empty Git repo in specified directory. |
git log | Display the entire commit history using the default format. |
git log <branch> .. | List commits that are present on current branch and not merged into <branch. |
git log ..<branch> | List commits that are present on <branch> and not merged current branch` |
git reflog | List operations (like checkouts, commits etc.) made on local repository. |
git log <since> ..<until> | Show commits that occur between <since> and <until> . Args can be a commit ID, branch name, HEAD, or any other kind of revision reference. |
git log -<limit> | Limit number of commits by <limit> . E.g. git log -5 will limit to 5 commits. |
git log -p | Display the full diff of each commit. |
git log -- <file> | Only display commits that have the specified <file> . |
git log --follow <file> | Lists version history for a file, including renames. |
git log --author=”<pattern> ” | Search for commits by a particular author. |
git log --graph --decorate | List commits in a text based graph with references labels. |
git log --grep=”<pattern> ” | Search for commits with a commit message that matches <pattern> . |
git log --oneline | List each commit in a single line. |
git log --stat | Include which files were altered and the relative number of lines that were added or deleted from each of them. |
git log --stat -M | Show all commit logs with indication of any paths that moved |
git merge <branch> | Merge <branch> into the current branch. |
git merge <branch> <name> | Merge <branch> from the <name> repository into the current branch. |
git mv <existing-path> <new-path> | Change an existing file path and stage the move. |
git pull <name> | Fetch the specified remote’s copy of current branch and merge it into the local copy. git pull is a combination of git fetch and git merge . |
git pull --tags <name> | Fetch the remote tags and merge them into the local copy. |
git pull --rebase <name> | Fetch the remote’s copy of current branch and rebase it into the local copy. |
git push <name> <branch> | Push the branch to <name> , along with necessary commits and objects. Creates named branch in the remote repo if it doesn’t exist. |
git push <name> --all | Push all local branches to the specified <name> . |
git push <name> --force | Force the git push even if it results in a non-fast-forward merge. |
git push <name> --tags | Push all local tags to the specified <name> . |
git push -u <name> <branch> | Push local branch to remote repository. |
git rebase <branch> | Apply any commits of the current branch onto <branch> . |
git rebase -i <branch> | Interactively rebase current branch onto <branch> . |
git reflog | Show a log of changes to the local repository’s HEAD. Add --relative-date flag to show date info or --all to show all refs. |
git remote -v | Show remote name and url. |
git remote add <name> <url> | Add a remote named <name> for the repository at <url> . |
git remote get-url --all <name> | Retrieve all the URLs for a remote. |
git remote get-url --push <name> | Retrieve only the push URLs for a remote. |
git remote prune <name> | Delete stale references associated with <name> . |
git remote prune --dry-run <name> | Report what branches associated with <name> will be pruned, but do not actually prune them. |
git remote remove <name> | Remove the remote named <name> . |
git remote rename <old> <new> | Rename the remote named <old> to <new> . |
git remote set-branches <name> <branch> | Change the list of branches tracked by the named remote. |
git remote set-branches --add <name> <branch> | Add to the list of branches tracked by the named remote. |
git remote set-head <name> <branch> | Set the default branch for the named remote. |
git remote set-head -a <name> | Query the named remote to determine its HEAD. |
git remote set-head -d <name> | Delete the default branch for the named remote. |
git remote set-url <name> <newurl> <oldurl> | Change URLs for the remote. |
git remote set-url --push <name> <newurl> <oldurl> | Change only push URLs for the remote. |
git remote set-url --add <name> <newurl> | Add URLs for the remote. |
git remote set-url --add --push <name> <newurl> | Add only push URLs for the remote. |
git remote set-url --delete <name> <url> | Delete URLs for the remote. |
git remote set-url --delete [--push] <name> <url> | Delete only push URLs for the remote. |
git remote show <name> | Give some information about the remote <name> and its mapping to local. |
git remote update <name> | Fetch updates for <name> . |
git remote update <remote>) | Fetch updates for remote <groups> in the repository as defined by remotes. |
git remote show <name> | Show remote branches and their mapping to local. |
git reset | Reset staging area to match most recent commit, but preserve file changes locally. |
git reset <commit> | Reset the staging area to match <commit> , but preserve file changes locally. |
git reset <file> | Unstage <file> from the staging area, but preserve <file> changes locally. |
git reset --hard | Reset both the staging area and the local repository to match most recent commit. |
git reset --hard <commit> | Reset both the staging area and the local repository file changes to match <commit> . |
git revert <commit> | Create new commit that undoes all of the changes made in <commit> , then apply it to the current branch. |
git rm <file> | Delete <file> from local repository and stage the removal for commit. |
git show <commit> | Show the file changes for <commit> . |
git show <commit> :<file> | Show the file changes for <commit> and/or <file> . |
git stash | Save modified and staged file changes temporarily. |
git stash drop | Clear stach without applying it into local repository. |
git stash list | List stack-order of stashed file changes. |
git stash pop | Apply saved stash content into local repository and clear stash. |
git stash save "<stash> " && git stash | Save changes to a <stash> . |
git status | List which files are staged, unstaged, and untracked. |
git tag | List all tags. |
git tag <tag> | Tag the current commit. |
git tag -a <tag> -m "<message> " | Create a new tag named <tag> with the commit <message> . |
git tag -d <name> | Remove a tag from local repository. |