jump to content
Snippets and tips
  1. Home
  2. Holiday
  3. Posts
  4. Tools
  5. Tags
  6. Categories

Git

The one and only git - with the usual commands I often use.

Commands, config settings and how I am using git to help me take care of business.

Git is a distributed version control system. In comparison to subversion, this means that several locations can serve as a distribution point.

Config settings #

Pretty oneliner log #

The first setting defines an alias for a pretty log, which gives me a nice overview over resent history.

1
git config --global alias.lol  'log --all --graph --color --date-order --pretty=format:"%h %Cgreen%d%Creset %ar %Cred%s %Cblue%ce"'

Then git lol gives a nice colorful log of all branches. Ommit --all if only the current branch is of interest. --graph shows the merges to the left side. The remaining arguments are my preferences and are documented in the git manual.

Working with remotes #

1
2
3
git config --global push.default current
git config --global push.autosetupremote true
git config --global fetch.prune=true

Those settings remove the need to always set the tracking manually. The last line removes local branches that are merge and removed on the remote - as it is the case in pull requests.

Ignoring whitespace differences #

1
git config --global diff.ignoreallspace true

Especially on Windows the changing line endings are a nightmare. Most languages are not indent aware, hence reformatting the code often results in large commits.

Commands #

Branches #

I used git branch -b <new branch> before, but now am using git switch -c <new branch> instead. Switching between branches is best done with git switch <branch name> as it is more intuitive.

Adding files #

git add -A -n shows which files would be added by the command git add -A -v.

Pruning #

git pull -p cleans the local list of branches and removes those that no longer exist on the remote side.