Installing prerequisite
1 |
sudo apt-get install git-gui gitk meld kdiff3 |
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:
1 |
git config --global -e |
All Git setting can be set or viewed via terminal, i.e:
To view all settings
1 |
git config --list --show-origin |
Current settings of mergetool:
1 |
git config --global merge.tool |
Set the merge tool
1 |
git config --global merge.tool vimdiff |
All available options for setting a merge tools can be listed by:
1 |
git mergetool --tool-help |
here we config it for meld, kdiff3 and vim.
Kdiff3
Add the following to your .gitconfig
file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[diff] tool = kdiff3 guitool = kdiff3 [difftool] prompt = false [difftool "kdiff3"] path = /usr/bin/kdiff3 trustExitCode = false [merge] tool = kdiff3 [mergetool "kdiff3"] path = /usr/bin/kdiff3 keepBackup = false trustExitCode = false |
For Windows users:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
[core] editor = \"C:/Program Files (x86)/notepad++/notepad++.exe\" -multiInst -nosession autocrlf = true [pull] rebase = false [fetch] prune = false [rebase] autoStash = false [diff] guitool = kdiff3 [difftool "kdiff3"] path = C:/Program Files/KDiff3/kdiff3.exe cmd = \"C:/Program Files/KDiff3/kdiff3.exe\" \"$LOCAL\" \"$REMOTE\" [merge] tool = kdiff3 guitool = kdiff3 [mergetool "kdiff3"] path = C:/Program Files/KDiff3/kdiff3.exe cmd = \"C:/Program Files/KDiff3/kdiff3.exe\" \"$BASE\" \"$LOCAL\" \"$REMOTE\" -o \"$MERGED\" [user] name = <your-username> email =<your-email> |
Meld
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[diff] tool = meld [difftool "meld"] path = /usr/bin/meld trustExitCode = false [difftool] prompt = false [merge] tool = meld [mergetool "meld"] path = /usr/bin/meld trustExitCode = false [mergetool] keepBackup = false |
For Windows users:
1 2 3 4 5 6 7 8 9 10 |
[difftool "meld"] path = C:/Program Files (x86)/Meld/Meld.exe cmd = \"C:/Program Files (x86)/Meld/Meld.exe\" \"$LOCAL\" \"$REMOTE\" [diff] guitool = meld [mergetool "meld"] path = C:/Program Files (x86)/Meld/Meld.exe cmd = \"C:/Program Files (x86)/Meld/Meld.exe\" \"$BASE\" \"$LOCAL\" \"$REMOTE\" -o \"$MERGED\" |
Vim
1 2 3 4 5 6 7 8 9 10 11 |
[merge] tool = vimdiff conflictstyle = diff3 [mergetool] prompt = false [diff] tool = vimdiff [difftool] prompt = false [alias] d = difftool |
Username, Email and editor
1 2 3 4 5 |
[core] editor = /usr/bin/gedit [user] email = behnam.asadi@gmail.com name = behnam.asadi |
Adding Alias
[alias]
1 |
graph = log --all --decorate --graph --oneline |
or add it via terminal:
1 |
git config --global alias.graph 'log --all --decorate --graph --oneline' |
SSH key
1 |
ssh-keygen |
and upload your public key
/home/<username>/.ssh/id_rsa.pub
into your GitHub account
Push into GitHub without a password using ssh-key
You have to change your remote type from http to git:
1 |
git remote set-url origin git@github.com:<username>/<repository_name>.git |
For example, if your repository is:
1 |
https://github.com/behnamasadi/data_structure_algorithm |
Then you have to run the following:
1 |
git remote set-url origin git@github.com:behnamasadi/data_structure_algorithm.git |
How to show the current branch in the Bash prompt
Edit ~/.bashrc
and find the following lines and uncomment them
1 2 3 4 5 |
if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' fi |
and replace them with
1 2 3 4 5 6 7 8 |
parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' } if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\] $(parse_git_branch)\[\033[00m\]\$ ' else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ ' fi |
Disabling Unix file permissions problem:
If you get the following message during a merge:
1 2 |
old mode 100755 new mode 100644 |
You have to disable the file mode. This usually happens when the repo is cloned between Windows and Linux/Unix machines.
1 |
git config --global core.filemode false |