git add -A
- Add modified, new, and deleted files.
git add -p file
- Enter patch mode to stage only parts of a file for commit
git add -u files/to/delete
- Stages deletions for commit
git add .
- Add all files for next commit
git am patch_file
- Apply a patch file that was generated by git format-patch
git apply --check patch_file
- Check to see if a patch will apply cleanly
git apply patch_file
- Apply a patch file that was generated by a diff command. patch_file should be outside the repo
git bisect bad
- Mark a commit as bad during a bisect
git bisect good
- Mark a commit as good during a bisect
git bisect reset
- Go back to where you were before starting bisect
git bisect start
- Start a debugging session
git blame -L start,end file
- See what commit/who is responsible for lines between start and end in file
git blame -w
- Ignore whitespace when running blame
git branch
- List all branches
git branch --merged
- Show the branches that have been merged into the current branch
git branch --no-merged
- Show the branches that haven't yet been merged into the current branch
git branch --set-upstream branch remote/branch
- Set a branch's remote tracking branch (pre-Git 8.0)
git branch -ar
- Show all branches on remotes
git branch -d -r remote/branch
- Delete a remote tracking branch
git branch -d branch
- Delete a branch
git branch -r
- Show remote branches for a repo.
git checkout -- file
- Retrieve last committed version of a file
git checkout --orphan new_branch
- Create a new branch without any history
git checkout --ours file
- During merge conflict resolution, choose the original/local version of a file.
git checkout --theirs file
- During merge conflict resolution, choose the new/remote version of a file.
git checkout -b branch
- Create a new branch and switch to it
git checkout -b new_branch remote/branch
- Create and switch to a new branch that tracks a remote repo's branch
git checkout -t -b branch_name remote/branch_name
- Create a new branch tracking a remote branch
git checkout branch
- Switch to a different branch
git checkout branch -- file
- Checkout a file's version from another branch
git checkout branch~commitNum -- fileOrDirectory
- Restore a file or directory from a previous commit. commitNum refers to the number of commits to go back, starting with 0
git checkout commit file/to/restore
- Restore a file or directory from a previous commit.
git cherry-pick commit
- Apply a commit (e.g. from another branch) to your current branch
git clean -f -d
- Remove all untracked files and directories from your working directory.
git clone --bare url name
- Clone a repo as a bare repo
git clone repo.bundle -b branch folder
- Open a Git bundle file.
git clone url folderNameToCreate
- Clone a remote repo
git commit --amend
- Replace the last commit with your current stage
git commit --amend --date="$(date -R)"
- Update last commit's author date to the current time
git commit --amend -m "message..."
- Change message of last commit
git commit -m "message..."
- Commit all selected files
git config --global core.excludesfile '~/.gitignore'
- Set up global gitignore file
git config --list
- List all configuration settings
git config receive.denyCurrentBranch ignore
- Tells repo to allow pushes into its working directory.
git config user.email "email"
- Set the commit email for the current repo
git config user.name "name"
- Set the commit user name for the current repo
git diff
- Show what you've modified but not yet staged
git diff --cached
- Show what you've staged
git diff --check
- Check modified, unstaged files for whitespace errors
git diff > [description]-[issue-number]-[comment-number].patch
- Create a simple git patch
git diff commit1 commit2
- Show the diff between two commits
git fetch remote
- Fetch changes from remote repo, but don't automatically merge them with your working directory
git filter-branch --tree-filter 'rm -f file' HEAD
- Remove a file from your entire commit history (will change all commit hashes)
git format-patch branch --stdout > filename.patch
- Save a patch to a file
git format-patch commit_id -- file(s)
- Create a patch of files that aren't in the current working directory
git format-patch commit_id file(s)
- Create a patch of specific files (space separated) in a specific commit
git format-patch target_branch
- Creates an emailable patch file for each commit in your current branch that you want to apply to target_branch
git fsck
- Check your repo for integrity issues
git gc
- Ask git to manually pack up extra objects in your repo
git init --shared
- Initialize a repo and automatically set up group write permissions
git log
- Show history of commits for current repository
git log -- file
- Show commits that affected that file
git log --author='name_or_email'
- Search through commits by author
git log --grep "search"
- Search through commit messages
git log --since="relative_time_or_date"
- See commits since a relative time or a date (e.g. yesterday)
git log --stat
- Show changed files after each commit record
git log --until=”relative_time_or_date”
- See commits up to a relative time or a date
git log -g
- Check your repo's reflog (where your HEAD has been)
git log -p
- Show the diff after each commit record
git log -S "search" --source --all
- Search through commit content
git log branch1 --not branch2
- List commits that are in branch1 but not in branch2
git log master ^origin/master
- See commits that are in master but not in origin/master
git log origin/master..HEAD
- Show commits you're about to push up
git ls-files --others
- List untracked files, including those ignored by .gitignore
git merge --squash -s subtree --no-commit branch
- Merge in changes from a branch that contains a different project (see read-tree)
git merge branch
- Merge branch into the branch you're currently on
git mv file_from file_to
- Rename a file
git pull --rebase
- Pull and rebase your remote onto your local repo
git pull -Xours user@host:path/to/repo.git
- Merge a remote repository into your current repository.
git push -u remote branch
- Push a branch to a remote repo and set new remote branch as local branch's tracking branch
git push remote --tags
- Push all tags to remote
git push remote :branch
- Delete a branch from a remote repo
git read-tree --prefix=directory/ -u branch
- Bring a branch that contains a different project into your current branch in a specific directory
git rebase -i HEAD~n
- Use interactive rebase to squash the last n commits into one
git rebase branch
- Replay the changes from branch on to the branch you're currently on to get them in sync
git remote
- Show remote repos for the current repo
git remote add name url
- Add a remote repo to the current repo
git remote rm name
- Remove a remote repo from the current repo
git remote show remote
- Show info about a remote repo
git reset --hard
- Reset modified files to their state in the last commit
git reset HEAD .
- Remove files selected for next commit
git revert hash
- Revert to a previous commit
git revert master@{"relative_time_or_date"}
- Revert to a previous commit at a relative time or date
git rev-list --all | xargs git grep regex
- Search commit history for changes matching a regex
git rm --cached file
- Removes a file from the repo but not the local filesystem
git rm file
- Remove file from repo and the filesystem
git show commit
- Show all the changes for a given commit.
git stash
- Stash the changes in your working directory so you can come back to that state later
git stash apply stash@{0}
- Apply your last stash back to your working directory
git stash list
- List your stashes
git status
- Show git status, including what files are modified, new, deleted
git submodule add url
- Add another git project as a submodule of your current project
git submodule init
- Initialize a repo which contains submodules
git submodule update
- Download the submodules repo for a repo containing submodules
git tag
- Show tags for the current repo
git tag -a tag_name -m 'tag_message'
- Create an annotated tag with a message
git update-index --assume-unchanged file
- Have git ignore any change to a given file, but keep it in the repo
git whatchanged --since="relative_time_or_date"
- See what changed since a certain time