Perfectly Random

machine learning and stuff

Using Git

Git is a free, open source version control system. If you’re looking to learn to use Git, you might find the tutorial at Github extremely useful. Google “github git tutorial” for a horde of beautiful learning resources. You can also go to bitbucket, sign up for a free account and practice using a git tutorial. In this post, I point out various tips/tricks I used to make Git behave the way I want. This is nothing new, you can find this information all over the web. I just felt like I should list all these in one place.

Colored output from Git

This is simple. Run this command in a terminal:

git config --global color.ui auto

This command will add the following snippet to your ~/.gitconfig file.

ui = auto

Or, you can manually add the above snippet to your ~/.gitconfig file.

Setting up different user names and emails for different repositories

Git sets up your global (system wide) user name/email in ~/.gitconfig. You can do this via this command.

git config --global user.email myemail@myemail.com
git config --global user.name myusername

This will add the following code snippet to your ~/.gitconfig file.

[user]
email = myemail@myemail.com
name = myusername

But if you maintain different user names/emails for different repositories, then you need to set up the user name/email for every repository independently. You can do this by typing this command inside the repository.

git config user.email myemail@myemail.com
git config user.name myusername

The default option for git config is --local so you don’t need to type out --local specifically.

The above commands will add the same snippet as before, but this time to your ./.git/config file.

This post is the part of the Using Git series:

  1. Using Git
  2. Using Git 2
  3. Using Git 3