Skip to content

Instantly share code, notes, and snippets.

@belgoros
Created August 31, 2020 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save belgoros/da1c8ceaca9563441dc37bbecea7b219 to your computer and use it in GitHub Desktop.
Save belgoros/da1c8ceaca9563441dc37bbecea7b219 to your computer and use it in GitHub Desktop.
Customizing Git - Git Configuration

Customizing Git - Git Configuration

Setup your credentials

git config --global user.name "Firstname Lastname"
git config --global user.email "your.email@example.org"

Avoid merge commits for pulling

By default, Git runs the git fetch followed by the git merge command if you use the git pull command. You can configure git to use git rebase instead of git merge for the pull command via the following setting:

git config --global branch.autosetuprebase always

Color Highlighting

git config --global color.ui auto

Configure Git on Windows to properly handle line endings

On Windows systems you can tell Git to convert line endings during a checkout to CRLF and to convert them back to LF during commit:

git config --global core.autocrlf true

Configure Git on Linux and Mac to properly handle line endings

On Linux and Mac you can tell Git to convert CRLF to LF with the following setting:

git config --global core.autocrlf input

Setup a global .gitignore file

Create a .gitignore_global file (you can choose a name you find easier to understand) in your User folder (C:\Users\{your user name}) for most Windows PCs, Users/{username} on a Linux/Unix based machine.

Run in your Bash terminal or Windows console (command prompt), adapt the file name if you used a different one:

git config --global core.excludesfile ~/.gitignore_global

Setup custom aliases if you are lazy to always tape in complete commands

Oh My ZSH already has most of them defined, just check them out by running alias in your terminal.

git config --global alias.co checkout #=> Run `git co` => the same as _git checkout_
git config --global alias.st status #=> Run `git st` => the same as _git status_
git config --global alias.br branch #=> Run git br => the same as _git branch_
git config --global alias.cob checkout -b #=> Run git cob => the same as _git checkout -b_
git config --global alias.hist log --abbrev-commit --pretty=oneline

Run git hist to see some abbreviated commit history.

Example:

  git hist -5 #=> will display a nice history for the last 5 commits

Display your global git settings

git config --global --list

You can find more about it in Git docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment