Mastering git, Part 1, setting up git environment, GUI, mergetool, difftool

Installing prerequisite

Configuring Git Environment

First config your environment and set a proper merge/ diff tool.  The settings in Linux are under/home/<username>/.gitconfig.    If you don’t know where this file is located in your OS You can easily edit this file by:

All Git setting can be set or viewed via terminal, i.e:

To view all settings

Current settings of mergetool:

Set the merge tool

All available options for setting a merge tools can be listed by:

here we config it for meld, kdiff3 and vim.


Add the following to your .gitconfig file

For Windows users:



For Windows users:


Username, Email and editor

Adding Alias


or add it via the terminal:

SSH key

and upload your public key, located at
into your GitHub account

If you have multiple accounts, you can create the following config file and save it under :


If you copy your key from a machine to your  .ssh directory, the permissions are too open and you  will get

So you need to:

Also, /home/<username>/.ssh/ the directory itself must be writable only by you:

Add the keys to ssh-agent:

and list them:

confirm the connection:

passphrases for SSH keys

if someone gains access to your machine, the attacker can gain access to every system that uses that key. You can add a passphrase to your SSH key to encrypt it. To avoid entering the passphrase every time you connect, you can securely save your passphrase in the SSH agent.

Change the passphrase for an existing private key without regenerating the keypair:

Change the passphrase comment:


Push into GitHub without a password using ssh-key

You have to change your remote type from http to git:

For example, if your repository is:

Then you have to run the following:

How to show the current branch in the Bash prompt

Edit ~/.bashrc and find the following lines and uncomment them

and replace them with

1, 2

Disabling Unix file permissions problem:
If you get the following message during a merge:

You have to disable the file mode. This usually happens when the repo is cloned between Windows and Linux/Unix machines.

Colors in Gitk

Yellow: Commit with the yellow circle is the HEAD. Gitk jumps to this commit once it got opened.
Red: Commit with a red circle is your uncommitted changes.
Blue: All other commits are shown in the blue circle.
Green: Local branches names are shown in green,
Orange, and green:  remote branch names are shown in a combination of orange and green, with the orange section being the remote name and the green section being the branch name.

Ignore list

you can use .ignore and .git/info/exclude


you can use .gitattributes and .git/info/attributes

Refs: [1]


How to get the root of Git repository

How to commit part of a file

You can use:


and then


If you are using git-gui, you can mark chunks that you want to have included in the commit by right-clicking them and selecting: “Stage Lines For Commit”


Refs: [1]

0 0 votes
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x