git
Quick reference for git
commands.
Commands
- 📄 means the command is built-in.
- ✚ means the command is available from tj/git-extras.
- ⛓️ means the command is available from nvie/git-toolbelt.
Subcommand | Docs | Description |
---|---|---|
abort | ✚ | Abort a revert, rebase, merge or cherry-pick |
alias | ✚ | Define, search and show aliases |
archive-file | ✚ | Zip the repository |
authors | ✚ | Generate an AUTHORS file |
browse | ✚ | Open the repository in the browser |
browse-ci | ✚ | Open the CI pipeline in the browser |
brv | ✚ | Pretty-print branches with their last commit |
changelog | ✚ | Generate a HISTORY/CHANGE file content |
clear | ✚ | Clear unstage changes and remove untracked files (includes ignored files) |
clear-soft | ✚ | Clear unstage changes and remove untracked files (excludes ignored files) |
count | ✚ | Count the number of commits |
extras | ✚ | Show the man page of git-extras |
fork | ✚ | Fork and clone a repository |
ignore | ✚ | Show ignored patterns |
ignore-io | ✚ | Generate .gitignore from gitignore.io |
lock | ✚ | Lock a file from being changed in the repository |
locked | ✚ | List all locked files |
obliterate | ✚ | Remove a file from the entire history of a git repository |
root | ⛓️ | Show the root directory of the repository |
summary | ✚ | Show commit summary |
show-tree | ✚ | Show commit tree |
standup | ✚ | Show a user's contributions in the past n days |
unlock | ✚ | Unlock a file from being changed in the repository |
Snippets
warning
Some of the snippets changes commit history. Use with caution.
Stage case-sensitive file changes
git mv --force old_name NEW_NAME
Remove commits after a certain commit
git rebase --committer-date-is-author-date -i <commit-hash>^
Reset author
- Configure the author name and email. (Add
--global
to set the author globally.)
git config user.name "New Author Name"
git config user.email "<email@address.example>"
- Rewrite the commit history.
git rebase -r '<since-commit-hash>' --exec 'git commit --amend --no-edit --reset-author'
or from the top
git rebase -r --root --exec 'git commit --amend --no-edit --reset-author'
Remove ignored files from local file system
This resets the local file system to a clean state. e.g. Remove installed node_modules
or built files.
git clean -fdX
Remove checked-in ignored files
- Update
.gitignore
to exclude the files. - Remove the files from the repository.
git rm --cached `git ls-files -i -c --exclude-from=.gitignore`
- Commit the changes.