Collection of
git-tips, want to add your tips? Checkout contributing.md
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
- Overwrite pull
- List of all files till a commit
- Git reset first commit
- 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
- 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
- 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 including untracked files
- 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
masterbranch - 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.
- 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.
- 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.
- 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.
- List ignored files.
- Status of ignored files.
- Commits in Branch1 that are not in Branch2
- 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
- File diff between staging and the last file version.
- Extract file from another branch.
- List only the root and merge commits.
- Merge previous two commits into one.
- 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
git help everydaygit help -ggit fetch --all && git reset --hard origin/mastergit ls-tree --name-only -r <commit-ish>git update-ref -d HEADgit diff --name-only --diff-filter=Ugit diff-tree --no-commit-id --name-only -r <commit-ish>git diffgit diff --cachedgit diff HEADgit branch --merged mastergit checkout -git branch --merged master | grep -v '^\*' | xargs -n 1 git branch -dgit branch -vvgit branch -u origin/mybranchgit branch -d <local_branchname>git push origin --delete <remote_branchname>Alternatives:
git push origin :<remote_branchname>git checkout -- <file_name>git revert <commit-ish>git reset <commit-ish>git commit -v --amendgit commit --amend --author='Author Name <[email protected]>'git commit --amend --reset-author --no-editgit remote set-url origin <URL>git remoteAlternatives:
git remote showgit branch -agit branch -rgit add -pcurl http://git.io/vfhol > ~/.git-completion.bash && echo '[ -f ~/.git-completion.bash ] && . ~/.git-completion.bash' >> ~/.bashrcgit 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 statusgit stashAlternatives:
git stash savegit stash save -uAlternatives:
git stash save --include-untrackedgit stash listgit stash apply <stash@{n}>git stash popAlternatives:
git stash apply stash@{0} && git stash drop stash@{0}git stash clearAlternatives:
git stash drop <stash@{n}>git checkout <stash@{n}> -- <file_path>Alternatives:
git checkout stash@{0} -- <file_path>git ls-files -tgit ls-files --othersgit ls-files --others -i --exclude-standardgit worktree add -b <branch-name> <path> <start-point>git worktree add --detach <path> HEADgit rm --cached <file_path>Alternatives:
git rm --cached -r <directory_path>git clean -ngit clean -fgit clean -f -dAlternatives:
git clean -dfgit submodule foreach git pullgit cherry -v masterAlternatives:
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 checkout feature && git rebase @{-1} && git checkout @{-2} && git merge @{-1}git archive master --format=zip --output=master.zipgit add --all && git commit --amend --no-editgit fetch -pAlternatives:
git remote prune origin git rev-list --reverse HEAD | head -1git log --pretty=oneline --graph --decorate --allAlternatives:
gitk --allgit subtree push --prefix subfolder_name origin gh-pagesgit subtree add --prefix=<directory_name>/<project_name> --squash [email protected]:<username>/<project_name>.git mastergit subtree pull --prefix=<directory_name>/<project_name> --squash [email protected]:<username>/<project_name>.git mastergit bundle create <file> <branch-name>git clone repo.bundle <repo-dir> -b <branch-name>git rev-parse --abbrev-ref HEADgit update-index --assume-unchanged Changelog; git commit -a; git update-index --no-assume-unchanged Changeloggit rebase --autostashgit fetch origin pull/<id>/head:<branch-name>Alternatives:
git pull origin pull/<id>/head:<branch-name>git describe --tags --abbrev=0git diff --word-diffgit update-index --assume-unchanged <file_name>git update-index --no-assume-unchanged <file_name>git clean -X -fgit checkout <deleting_commit>^ -- <file_path>git checkout <commit-ish> -- <file_path>git config --global branch.autosetuprebase alwaysgit config --listgit config --global core.ignorecase falsegit config --global help.autocorrect 1git name-rev --name-only <SHA-1>git clean -fd --dry-rungit commit --fixup <SHA-1>git rebase -i --autosquashgit commit -am <commit message>git check-ignore *git status --ignoredgit log Branch1 ^Branch2git config --global rerere.enabled 1git diff --name-only | uniq | xargs $EDITORgit count-objects --human-readablegit gc --prune=now --aggressivegit instaweb [--local] [--httpd=<httpd>] [--port=<port>] [--browser=<browser>]git log --show-signaturegit config --global --unset <entry-name>git checkout --orphan <branch_name>git diff --stagedgit show <branch_name>:<file_name>git log --first-parentgit rebase --interactive HEAD~2git checkout master && git branch --no-mergedgit 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-verifygit log --follow -p -- <file_path>git clone -b <branch-name> --single-branch https://github.com/user/repo.gitgit checkout -b <branch-name>git config core.fileMode false