Monday, 2 March 2015

“No tracking information on current branch” while doing git pull

Git continues to amuse me. There sheer options and versatility that you get in creating branches, merges and tracking commits, make it a such a powerful source code repository. It also means a steep learning curve for a lifelong TFSVC and VSS .

This is the first of a series of posts, I will write about some common start up mistakes I have done or seen others doing. I hope it would be helpful for the wider community.

To demonstrate my git repository clearly, I am using posh-git, which gives a view of my current git branch and also shows local, active and remote branches in different colours

Created branch but failed to created tracking information.

This is one of the most common mistakes. To describe it, I start with listing all my local and remote branch. To do that I type in “git branch –a” as shown

GitBranchAll 

As you can see with the asterisk against master that my current local repository is “master”.

Now lets say that I want to work on the remote “TeamBuild/Staging” branch . To do that I created a new local branch naming it same as the server

GitBranchCheckoutNew

The new branch is created successfully and I am switched on to the new branch as shown by running another “git branch –a”

GitBranchCheckoutPostCreation

You can see that the current branch is now switched to “teambuild/staging”. All good so far.

However, when I do a “git pull”, I got the following message.

GitPullNoTrackingBranch

So, what has gone wrong. A quick peek into the Git config file, tells me that the new branch is created without tracking it to the remote branch with the same name.

GitConfigBefore

As you can see that there is no mention of the newly created branch.

Cause

The reason no tracking information was created is because Git is case sensitive. So, the branch“teambuild/staging” is not same as “TeamBuild/Staging”. For windows / TFS users, they look the same but Git would treat them as two separate branches.

Resolution

You can add tracking information in a branch using the “git branch –u” command. So typing the following will add tracking information with the remote branch and you will be be up and running

GitTrack

You can see that the tracking information is added by peeking into the git config file. Notice the couple of lines in the end to see details of the /staging/teambuild branch added to git config.

GitConfigAfter

Don’t try it at home

You will git into a bit of a pickle if are using Windows and you create two local branches that differentiate just by casing.  Since git creates a folder within the refs/head folder in the git directory. If the names vary only by casing, it would have two branches tracked on one folder which would confuse it. So be mindful with casing while working with Git branches.