Skip to content
Fumler edited this page Oct 15, 2012 · 3 revisions

How to use Git Bash with proper merging tool

Installing Git

The first thing you need is to download Git, most of you probably just downloaded GitHub for Windows but not Git itself. To download Git go to Git-SCM. Just follow the installation tips from there and pick the standard options unless you prefer otherwise. The standard installation includes everything you need to get started, including Git Bash, which is the tool we will be using for updating our repos. Once Git is installed, continue to the next step.

Installing KDiff3

The second thing you need is a tool to deal with conflicts, the best and easiest one I found so far is KDiff3. Go to the download page and download KDiff3, install it to an easy location, e.g. "C:\Program Files\KDiff3". Just follow the installation instructions, and if you do not want a Norwegian version of it, untick "Translations" during install. You can also change this in the settings after install. Continue to the next step.

Setting up KDiff3 with Git Bash

Once you have downloaded KDiff3 and Git you have to put them together. First thing you should do is settings the path to KDiff3 in your PATH environment variable;

  1. Click your "Start"-button (probably) to the bottom left of your main screen.
  2. Right-click "Computer" and click "Properties"
  3. On the left hand side menu, click "Advanced System Settings"
  4. On the "Advanced" tab, click "Environment Variables"
  5. In the "System variables" pane, locate the "PATH" variable, and add your KDiff3 folder to this, e.g. ;C:\Program Files\KDiff3.
  6. Click Ok, Ok, Ok.
  7. Open Git Bash
  8. Type: git config --global merge.tool kdiff3 and git config --global mergetool.kdiff3.path "C:/Program Files/KDiff3/kdiff3.exe"

How to use Git Bash

Now, to update your local repo from the remote repo, you can do git pull. This will download the remote files and merge them with your own if no conflict. If you have changes on your local repo you can do 'git status' to see which files have been modified. There are 2 color codes to look for here;

  • Red, un-committed, modified files
  • Green, committed, modified files

So, if you have red files, simply do git add -A to add all files to your "stage" (means which files you want to potentially do stuff with) or you can do git add yourfile yourfile2 yourfile3 etc. Now you can do either:

  • git commit or
  • git commit -m "Your message here"

The latter simply adds a custom message, and the former opens a textfile which you can edit, where you add a commit title and commit message.

After you feel ready, you can push the changes to the remote repo, you do this by writing git push. It might tell you to do a git pull first if it notices there are changed files on the remote repo. Then you just follow the instructions.

A little tip here as well is if you already have GitHub For Windows you can open your repo with that, and then go to tools and choose "Open a shell here" so you don't have to log in and navigate to the correct folder in Git Bash.

Now if you get a conflict you do git mergetool, this opens up the KDiff3 program. To figure out how this work, go to next step.

How to use KDiff3

KDiff3 is a graphical interface where you can solve merge conflicts very easily. It has four panes. Three at the top and one at the bottom.

The top panes are divided from left to right with pane IDs being A, B and C.

  • A is the previous remote push
  • B is your push
  • C is the conflicting push

Now, the bottom pane tells you where all the conflicts are, and to solve them you simply right-click the conflict and choose either A, B or C's code. When you are happy, you simply Save (CTRL+S) and re-push your changes!

Here is a screenshot of how it looks: KDiff3

Voila! You are now an expert.

Clone this wiki locally