Git - Tips

From XennisWiki
Jump to: navigation, search

Tip for the revision control system Git


Display all configurations

git config --list

Set (local) name and e-mail

Further information: Git Tip: git config and for local (not global) config

Set name and mail global

git config --global "YOUR NAME"
git config --global ""

Set name and mail local for the current repository

git config "YOUR NAME"
git config ""

These local settings will be saved in the MY-REPO/.git/config file.

Store username and password

Store your credential (name and password) for a Git repository

git config credential.helper store

Next time you have to enter your credentials, they will be stored.

Push only current branch

git config push.default current


Set editor

Set globally vim as editor

git config --global core.editor vim

Enable color for git diff

Use the following command to enable colored output in the command line:

git config --global color.ui auto

Configure alias

For example define st as alias for status

git config --global status

Configure proxy

Source: Remote operations via http and a proxy

Configure proxy

git config --global http.proxy http://YOUR-PORXY.COM:PORT-NUMBER

Get proxy settings

git config --get http.proxy

Delete proxy settings

git config --global --unset http.proxy


Ignore files

see Git - Ignore

Ignore files locally only

To ignore files locally only add them to the .git/info/exclude file. The format is the same like the .gitignore file.

Checkout with LF (line feed)

Add the file .gitattributes to the root directory of your repository. Example for check in and out all files with the extension txt always with LF (line feed):

# Declare files that will always have LF line endings on checkout.
*.txt text eol=lf

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary

Well formatted file

Use Markdown markup language for format your file.

Show commits between two tags

git log [-p] Tag_A..Tag_B



git submodule update --recursive --init

Move a submodule

Simply use git mv

git mv path/mySubmodule new/fuu

Reset all submodules

git submodule foreach git reset --hard


In .git/hooks are several hooks by default. To use them copy for instance .git/hooks/pre-push.samle to .git/hooks/pre-push.

To run Go tests before push add the file .git/hooks/pre-push:

go test ./...

Update the local list of remote branches

#git remote update origin --prune
git remote prune origin


Change author name / mail in history / log

Use the Bash script Changing author info. Afterwards use the command:

git push --force origin

Rename a (remote) branch

The following three steps are required to rename a remote branch:

# Create a branch with the new name
git branch -m OLD-NAME NEW-NAME
# Push the created branch
git push origin NEW-NAME
# Delete the old branch
git push origin :OLD-NAME

Remove large files from history

Further information: BFG Repo-Cleaner usage

(1) Clone your repository with the option --mirror and (2) run BFG (use option --private to prevent former id in commit message)

git clone --mirror git://
java -jar bfg.jar --private --strip-blobs-bigger-than 100M example.git

Clean the repository and push it

cd example.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push

Assume file was not changed

git update-index --assume-unchanged <file>


Start a bisect with good commit HEAD~30 and bad commit HEAD

# Short form of: git bisect start; git bisect bad HEAD; git bisect good HEAD~30
git bisect start HEAD HEAD~30

Reset bisect

gib bisect reset

Run bisect by a program. In this case grep is used which exits with 0 (true) or 1 (false).

git bisect run grep "<pattern>"

See also