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 settings can be set or viewed via terminal, i.e:

If the URI of your repository is file-based, you can enable cloning by:

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.

Kdiff3

Add the following to your .gitconfig file

For Windows users:

 

Meld

For Windows users:

Vim

Username, Email, and editor

Adding Alias

[alias]

or add it via the terminal:

Multiple GitHub accounts with SSH keys

First, create your keys:

and upload your public key, located at
/home/<username>/.ssh/id_rsa.pub
into your GitHub account

If you have multiple accounts, you can create the following config file and save it under /home/<username>/.ssh/config directory. The Host value could be anything, but you should be persistent: in our case, these values are:

  • github.com-first-account
  • github.com-second-account

The first-account and second-account are your real GitHub user account ID

The content of the config file:

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, first:

SSH needs two things in order to use ssh-agent: an ssh-agent instance running in the background, and an environment variable set that tells SSH which socket it should use to connect to the agent (SSH_AUTH_SOCK IIRC). If you just run ssh-agent then the agent will start, but SSH will have no idea where to find it [1]

Then add the key to ssh-agent:

and list them:

confirm the connection:

or directly:

you can debug everything:

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:

now, while cloning repositories instead of :

you use:

and

For existing repositories:

and

Another solution is to have only one active SSH key in the ssh-agent at a time:

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

gitattributes

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:

or

and then

not

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]

Long filename problem in Git for Windows

Refs: [1]

0 0 votes
Article Rating
Subscribe
Notify of
guest

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

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x