Collection of
git-tips
, want to add your tips? Checkout contributing.md
English | 中文 | Русский | 한국어 | Tiếng Việt | 日本語 | नेपाली
- git-tip - A handy CLI to make optimum use of these tips. (Here in Docker container)
P.S: All these commands are tested on git version 2.7.4 (Apple Git-66)
.
- Everyday Git in twenty commands or so
- Show helpful guides that come with Git
- Search change by content
- Show changes over time for specific file
- Remove sensitive data from history, after a push
- Sync with remote, overwrite local changes
- List of all files till a commit
- Git reset first commit
- Reset: preserve uncommitted local changes
- List all the conflicted files
- List of all files changed in a commit
- Unstaged changes since last commit
- Changes staged for commit
- Show both staged and unstaged changes
- List all branches that are already merged into master
- Quickly switch to the previous branch
- Remove branches that have already been merged with master
- List all branches and their upstreams, as well as last commit on branch
- Track upstream branch
- Delete local branch
- Delete remote branch
- Delete local tag
- Delete remote tag
- Undo local changes with the last content in head
- Revert: Undo a commit by creating a new commit
- Reset: Discard commits, advised for private branch
- Reword the previous commit message
- See commit history for just the current branch
- Amend author.
- Reset author, after author has been changed in the global config.
- Changing a remote's URL
- Get list of all remote references
- Get list of all local and remote branches
- Get only remote branches
- Stage parts of a changed file, instead of the entire file
- Get git bash completion
- What changed since two weeks?
- See all commits made since forking from master
- Pick commits across branches using cherry-pick
- Find out branches containing commit-hash
- Git Aliases
- Saving current state of tracked files without commiting
- Saving current state of unstaged changes to tracked files
- Saving current state including untracked files
- Saving current state with message
- Saving current state of all files (ignored, untracked, and tracked)
- Show list of all saved stashes
- Apply any stash without deleting from the stashed list
- Apply last stashed state and delete it from stashed list
- Delete all stored stashes
- Grab a single file from a stash
- Show all tracked files
- Show all untracked files
- Show all ignored files
- Create new working tree from a repository (git 2.5)
- Create new working tree from HEAD state
- Untrack files without deleting
- Before deleting untracked files/directory, do a dry run to get the list of these files/directories
- Forcefully remove untracked files
- Forcefully remove untracked directory
- Update all the submodules
- Show all commits in the current branch yet to be merged to master
- Rename a branch
- Rebases 'feature' to 'master' and merges it in to master
- Archive the
master
branch - Modify previous commit without modifying the commit message
- Prunes references to remote branches that have been deleted in the remote.
- Retrieve the commit hash of the initial revision.
- Visualize the version tree.
- Visualize the tree including commits that are only referenced from reflogs
- Deploying git tracked subfolder to gh-pages
- Adding a project to repo using subtree
- Get latest changes in your repo for a linked project using subtree
- Export a branch with history to a file.
- Import from a bundle
- Get the name of current branch.
- Ignore one file on commit (e.g. Changelog).
- Stash changes before rebasing
- Fetch pull request by ID to a local branch
- Show the most recent tag on the current branch.
- Show inline word diff.
- Show changes using common diff tools.
- Don’t consider changes for tracked file.
- Undo assume-unchanged.
- Clean the files from
.gitignore
. - Restore deleted file.
- Restore file to a specific commit-hash
- Always rebase instead of merge on pull.
- List all the alias and configs.
- Make git case sensitive.
- Add custom editors.
- Auto correct typos.
- Check if the change was a part of a release.
- Dry run. (any command that supports dry-run flag should do.)
- Marks your commit as a fix of a previous commit.
- Squash fixup commits normal commits.
- Skip staging area during commit.
- Interactive staging.
- List ignored files.
- Status of ignored files.
- Commits in Branch1 that are not in Branch2
- List n last commits
- Reuse recorded resolution, record and reuse previous conflicts resolutions.
- Open all conflicted files in an editor.
- Count unpacked number of objects and their disk consumption.
- Prune all unreachable objects from the object database.
- Instantly browse your working repository in gitweb.
- View the GPG signatures in the commit log
- Remove entry in the global config.
- Checkout a new branch without any history
- Extract file from another branch.
- List only the root and merge commits.
- Change previous two commits with an interactive rebase.
- List all branch is WIP
- Find guilty with binary search
- Bypass pre-commit and commit-msg githooks
- List commits and changes to a specific file (even through renaming)
- Clone a single branch
- Create and switch new branch
- Ignore file mode changes on commits
- Turn off git colored terminal output
- Specific color settings
- Show all local branches ordered by recent commits
- Find lines matching the pattern (regex or string) in tracked files
- Clone a shallow copy of a repository
- Search Commit log across all branches for given text
- Get first commit in a branch (from master)
- Unstaging Staged file
- Force push to Remote Repository
- Adding Remote name
- List all currently configured remotes
- Show the author, time and last revision made to each line of a given file
- Group commits by authors and title
- Forced push but still ensure you don't overwrite other's work
- Show how many lines does an author contribute
- Revert: Reverting an entire merge
- Number of commits in a branch
- Alias: git undo
- Add object notes
- Show all the git-notes
- Apply commit from another repository
- Specific fetch reference
- Find common ancestor of two branches
- List unpushed git commits
- Add everything, but whitespace changes
- Edit [local/global] git config
- blame on certain range
- Show a Git logical variable.
- Preformatted patch file.
- Get the repo name.
- logs between date range
- Exclude author from logs
- Generates a summary of pending changes
- List references in a remote repository
- Backup untracked files.
- List all git aliases
- Show git status short
- Checkout a commit prior to a day ago
- Push a new local branch to remote repository and track
- Change a branch base
- Use SSH instead of HTTPs for remotes
- Update a submodule to the latest commit
git help everyday
git help -g
git log -S'<a term in the source>'
git log -p <file_name>
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch <path-to-your-file>' --prune-empty --tag-name-filter cat -- --all && git push origin --force --all
git fetch origin && git reset --hard origin/master && git clean -f -d
git ls-tree --name-only -r <commit-ish>
git update-ref -d HEAD
git reset --keep <commit>
git diff --name-only --diff-filter=U
git diff-tree --no-commit-id --name-only -r <commit-ish>
git diff
git diff --cached
Alternatives:
git diff --staged
git diff HEAD
git branch --merged master
git checkout -
Alternatives:
git checkout @{-1}
git branch --merged master | grep -v '^\*' | xargs -n 1 git branch -d
Alternatives:
git branch --merged master | grep -v '^\*\| master' | xargs -n 1 git branch -d # will not delete master if master is not checked out
git branch -vv
git branch -u origin/mybranch
git branch -d <local_branchname>
git push origin --delete <remote_branchname>
Alternatives:
git push origin :<remote_branchname>
git branch -dr <remote/branch>
git tag -d <tag-name>
git push origin :refs/tags/<tag-name>
git checkout -- <file_name>
git revert <commit-ish>
git reset <commit-ish>
git commit -v --amend
git cherry -v master
git commit --amend --author='Author Name <[email protected]>'
git commit --amend --reset-author --no-edit
git remote set-url origin <URL>
git remote
Alternatives:
git remote show
git branch -a
git branch -r
git add -p
curl -L http://git.io/vfhol > ~/.git-completion.bash && echo '[ -f ~/.git-completion.bash ] && . ~/.git-completion.bash' >> ~/.bashrc
git log --no-merges --raw --since='2 weeks ago'
Alternatives:
git whatchanged --since='2 weeks ago'
git log --no-merges --stat --reverse master..
git checkout <branch-name> && git cherry-pick <commit-ish>
git branch -a --contains <commit-ish>
Alternatives:
git branch --contains <commit-ish>
git config --global alias.<handle> <command>
git config --global alias.st status
git stash
Alternatives:
git stash save
git stash -k
Alternatives:
git stash --keep-index
git stash save --keep-index
git stash -u
Alternatives:
git stash save -u
git stash save --include-untracked
git stash save <message>
git stash -a
Alternatives:
git stash --all
git stash save --all
git stash list
git stash apply <stash@{n}>
git stash pop
Alternatives:
git stash apply stash@{0} && git stash drop stash@{0}
git stash clear
Alternatives:
git stash drop <stash@{n}>
git checkout <stash@{n}> -- <file_path>
Alternatives:
git checkout stash@{0} -- <file_path>
git ls-files -t
git ls-files --others
git ls-files --others -i --exclude-standard
git worktree add -b <branch-name> <path> <start-point>
git worktree add --detach <path> HEAD
git rm --cached <file_path>
Alternatives:
git rm --cached -r <directory_path>
git clean -n
git clean -f
git clean -f -d
git submodule foreach git pull
Alternatives:
git submodule update --init --recursive
git submodule update --remote
git cherry -v master
Alternatives:
git cherry -v master <branch-to-be-merged>
git branch -m <new-branch-name>
Alternatives:
git branch -m [<old-branch-name>] <new-branch-name>
git rebase master feature && git checkout master && git merge -
git archive master --format=zip --output=master.zip
git add --all && git commit --amend --no-edit
git fetch -p
Alternatives:
git remote prune origin
git rev-list --reverse HEAD | head -1
Alternatives:
git rev-list --max-parents=0 HEAD
git log --pretty=oneline | tail -1 | cut -c 1-40
git log --pretty=oneline --reverse | head -1 | cut -c 1-40
git log --pretty=oneline --graph --decorate --all
Alternatives:
gitk --all
git log --graph --pretty=format:'%C(auto) %h | %s | %an | %ar%d'
git log --graph --decorate --oneline $(git rev-list --walk-reflogs --all)
git subtree push --prefix subfolder_name origin gh-pages
git subtree add --prefix=<directory_name>/<project_name> --squash [email protected]:<username>/<project_name>.git master
git subtree pull --prefix=<directory_name>/<project_name> --squash [email protected]:<username>/<project_name>.git master
git bundle create <file> <branch-name>
git clone repo.bundle <repo-dir> -b <branch-name>
git rev-parse --abbrev-ref HEAD
git update-index --assume-unchanged Changelog; git commit -a; git update-index --no-assume-unchanged Changelog
git rebase --autostash
git fetch origin pull/<id>/head:<branch-name>
Alternatives:
git pull origin pull/<id>/head:<branch-name>
git describe --tags --abbrev=0
git diff --word-diff
git difftool [-t <tool>] <commit1> <commit2> <path>
git update-index --assume-unchanged <file_name>
git update-index --no-assume-unchanged <file_name>
git clean -X -f
git checkout <deleting_commit>^ -- <file_path>
git checkout <commit-ish> -- <file_path>
git config --global pull.rebase true
Alternatives:
#git < 1.7.9
git config --global branch.autosetuprebase always
git config --list
git config --global core.ignorecase false
git config --global core.editor '$EDITOR'
git config --global help.autocorrect 1
git name-rev --name-only <SHA-1>
git clean -fd --dry-run
git commit --fixup <SHA-1>
git rebase -i --autosquash
git commit --only <file_path>
git add -i
git check-ignore *
git status --ignored
git log Branch1 ^Branch2
git log -<n>
Alternatives:
git log -n <n>
git config --global rerere.enabled 1
git diff --name-only | uniq | xargs $EDITOR
git count-objects --human-readable
git gc --prune=now --aggressive
git instaweb [--local] [--httpd=<httpd>] [--port=<port>] [--browser=<browser>]
git log --show-signature
git config --global --unset <entry-name>
git checkout --orphan <branch_name>
git show <branch_name>:<file_name>
git log --first-parent
git rebase --interactive HEAD~2
git checkout master && git branch --no-merged
git bisect start # Search start
git bisect bad # Set point to bad commit
git bisect good v2.6.13-rc2 # Set point to good commit|tag
git bisect bad # Say current state is bad
git bisect good # Say current state is good
git bisect reset # Finish search
git commit --no-verify
git log --follow -p -- <file_path>
git clone -b <branch-name> --single-branch https://github.com/user/repo.git
git checkout -b <branch-name>
Alternatives:
git branch <branch-name> && git checkout <branch-name>
git config core.fileMode false
git config --global color.ui false
git config --global <specific command e.g branch, diff> <true, false or always>
git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/
git grep --heading --line-number 'foo bar'
git clone https://github.com/user/repo.git --depth 1
git log --all --grep='<given-text>'
git log --oneline master..<branch-name> | tail -1
Alternatives:
git log --reverse master..<branch-name> | head -6
git reset HEAD <file-name>
git push -f <remote-name> <branch-name>
git remote add <remote-nickname> <remote-url>
git remote -v
git blame <file-name>
git shortlog
git push --force-with-lease <remote-name> <branch-name>
git log --author='_Your_Name_Here_' --pretty=tformat: --numstat | gawk '{ add += <!-- @doxie.inject start -->; subs += <!-- @doxie.inject end -->; loc += <!-- @doxie.inject start --> - <!-- @doxie.inject end --> } END { printf "added lines: %s removed lines: %s total lines: %s
", add, subs, loc }' -
Alternatives:
git log --author='_Your_Name_Here_' --pretty=tformat: --numstat | awk '{ add += <!-- @doxie.inject start -->; subs += <!-- @doxie.inject end -->; loc += <!-- @doxie.inject start --> - <!-- @doxie.inject end --> } END { printf "added lines: %s, removed lines: %s, total lines: %s
", add, subs, loc }' - # on Mac OSX
git revert -m 1 <commit-ish>
git rev-list --count <branch-name>
git config --global alias.undo '!f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{${1-1}}; }; f'
git notes add -m 'Note on the previous commit....'
git log --show-notes='*'
git --git-dir=<source-dir>/.git format-patch -k -1 --stdout <SHA1> | git am -3 -k
git fetch origin master:refs/remotes/origin/mymaster
git merge-base <branch-name> <other-branch-name>
git log --branches --not --remotes
Alternatives:
git log @{u}..
git cherry -v
git diff --ignore-all-space | git apply --cached
git config [--global] --edit
git blame -L <start>,<end>
git var -l | <variable>
git format-patch -M upstream..topic
git rev-parse --show-toplevel
git log --since='FEB 1 2017' --until='FEB 14 2017'
git log --perl-regexp --author='^((?!excluded-author-regex).*)
git request-pull v1.0 https://git.ko.xz/project master:for-linus
git ls-remote git://git.kernel.org/pub/scm/git/git.git
git ls-files --others -i --exclude-standard | xargs zip untracked.zip
git config -l | grep alias | sed 's/^alias\.//g'
Alternatives:
git config -l | grep alias | cut -d '.' -f 2
git status --short --branch
git checkout master@{yesterday}
git push -u origin <branch_name>
git rebase --onto <new_base> <old_base>
git config --global url.'[email protected]:'.insteadOf 'https://github.com/'
cd <path-to-submodule>
git pull origin <branch>
cd <root-of-your-main-project>
git add <path-to-submodule>
git commit -m "submodule updated"