tip
stringlengths
10
365
title
stringlengths
11
98
git config --global rerere.enabled 1
Reuse recorded resolution, record and reuse previous conflicts resolutions.
git config --list
List all the alias and configs.
git branch --merged master
List all branches that are already merged into master
git log --oneline master..<branch-name> | tail -1
Get first commit in a branch (from master)
git checkout master && git branch --no-merged
List all branch is WIP
git stash show -p <stash@{n}>
Show the contents of any stash in patch form
git diff HEAD
Show both staged and unstaged changes
git diff-tree --no-commit-id --name-only -r <commit-ish>
List of all files changed in a commit
git log --perl-regexp --author='^((?!excluded-author-regex).*)$'
Exclude author from logs
git reset --keep <commit>
Reset: preserve uncommitted local changes
git push origin :refs/tags/<tag-name>
Delete remote tag
git var -l | <variable>
Show a Git logical variable.
git clean -fd --dry-run
Dry run. (any command that supports dry-run flag should do.)
git push -f <remote-name> <branch-name>
Force push to Remote Repository
git commit --amend --author='Author Name <email@address.com>'
Amend author.
git diff --ignore-all-space | git apply --cached
Add everything, but whitespace changes
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
Find guilty with binary search
git update-index --assume-unchanged Changelog; git commit -a; git update-index --no-assume-unchanged Changelog
Ignore one file on commit (e.g. Changelog).
git push -u origin <branch_name>
Push a new local branch to remote repository and track
git log --author='_Your_Name_Here_' --pretty=tformat: --numstat | gawk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s removed lines: %s total lines: %s ", add, subs, loc }' -
Show how many lines does an author contribute
git log Branch1 ^Branch2
Commits in Branch1 that are not in Branch2
git rm --cached <file_path>
Untrack files without deleting
git log --all --grep='<given-text>'
Search Commit log across all branches for given text
git log --show-notes='*'
Show all the git-notes
git reset <commit-ish>
Reset: Discard commits, advised for private branch
git config -l | grep alias | sed 's/^alias\.//g'
List all git aliases
git push --force-with-lease <remote-name> <branch-name>
Forced push but still ensure you don't overwrite other's work
git merge-base <branch-name> <other-branch-name>
Find common ancestor of two branches
git rebase master feature && git checkout master && git merge -
Rebases 'feature' to 'master' and merges it in to master
git commit --fixup <SHA-1>
Marks your commit as a fix of a previous commit.
git worktree add --detach <path> HEAD
Create new working tree from HEAD state
git log --branches --not --remotes
List unpushed git commits
git check-ignore *
List ignored files.
git checkout -
Quickly switch to the previous branch
git help everyday
Everyday Git in twenty commands or so
git diff --name-only | uniq | xargs $EDITOR
Open all conflicted files in an editor.
git clean -n
Before deleting untracked files/directory, do a dry run to get the list of these files/directories
git show <branch_name>:<file_name>
Extract file from another branch.
git log -<n>
List n last commits
git config --global <specific command e.g branch, diff> <true, false or always>
Specific color settings
git log --since='FEB 1 2017' --until='FEB 14 2017'
logs between date range
git ls-tree --name-only -r <commit-ish>
List of all files till a commit
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
Remove sensitive data from history, after a push
git difftool [-t <tool>] <commit1> <commit2> <path>
Show changes using common diff tools.
git ls-files --others -i --exclude-standard
Show all ignored files
git stash push -m <message>
Saving current state with message
git subtree push --prefix subfolder_name origin gh-pages
Deploying git tracked subfolder to gh-pages
git checkout <branch-name> && git cherry-pick <commit-ish>
Pick commits across branches using cherry-pick
git fetch origin pull/<id>/head:<branch-name>
Fetch pull request by ID to a local branch
git config --global alias.undo '!f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{${1-1}}; }; f'
Alias: git undo
git update-index --assume-unchanged <file_name>
Don鈥檛 consider changes for tracked file.
git branch -a --contains <commit-ish>
Find out branches containing commit-hash
git commit --amend --reset-author --no-edit
Reset author, after author has been changed in the global config.
git reset HEAD <file-name>
Unstaging Staged file
git revert <commit-ish>
Revert: Undo a commit by creating a new commit
git grep --heading --line-number 'foo bar'
Find lines matching the pattern (regex or string) in tracked files
git remote
Get list of all remote references
git cherry -v master
See commit history for just the current branch
git config --global core.autocrlf false
Prevent auto replacing LF with CRLF
git commit -v --amend
Reword the previous commit message
git commit --no-verify
Bypass pre-commit and commit-msg githooks
git notes add -m 'Note on the previous commit....'
Add object notes
git archive master --format=zip --output=master.zip
Archive the `master` branch
git remote set-url origin <URL>
Changing a remote's URL
git config --global color.ui false
Turn off git colored terminal output
git config --global alias.<handle> <command> git config --global alias.st status
Git Aliases
git branch -u origin/mybranch
Track upstream branch
git checkout <stash@{n}> -- <file_path>
Grab a single file from a stash
git log --graph --decorate --oneline $(git rev-list --walk-reflogs --all)
Visualize the tree including commits that are only referenced from reflogs
git log -S'<a term in the source>'
Search change by content
git ls-remote git://git.kernel.org/pub/scm/git/git.git
List references in a remote repository
git diff --name-only --diff-filter=U
List all the conflicted files
git instaweb [--local] [--httpd=<httpd>] [--port=<port>] [--browser=<browser>]
Instantly browse your working repository in gitweb.
git status --short --branch
Show git status short
git config --global pull.rebase true
Always rebase instead of merge on pull.
git config --global url.'git@github.com:'.insteadOf 'https://github.com/'
Use SSH instead of HTTPs for remotes
git clone https://github.com/user/repo.git --depth 1
Clone a shallow copy of a repository
git clean -f
Forcefully remove untracked files
git rev-list --reverse HEAD | head -1
Retrieve the commit hash of the initial revision.
git rebase --interactive HEAD~2
Change previous two commits with an interactive rebase.
git diff --cached
Changes staged for commit
git fetch origin master:refs/remotes/origin/mymaster
Specific fetch reference
git clean -f -d
Forcefully remove untracked directory