April 18, 2012
that the ripest might fall
Git is simply amazing when it comes to branching and merging. I probably have half a dozen branches, each with a unique feature I am working on. Git makes combining and working with branches so easy that it simply seems natural to store test-functionality on different branches, across multiple repositories, and between different developers.
…and HOLY CRAP is it fast!
That said I hit a problem today that I had to hunt down the answer to, so I am posting it here for easy reference in the future. The basic issue is that whenever you create a new branch that is then pushed to someone else as a remote branch, git automatically (as would be logical) associates those branches together because they share the same name. This makes future pushes easy and allows other users to continually get updates when you have commits you want to make available.
The problem occurs when you try to PULL from that new remote branch (because the users or repository has made some of their own changes.) Git does NOT automatically associate pulls with the remote branch of the same name, even though this associates pushes. So how do you fix this? The error message says to modify your config file and look at the git-pull man page, but that could quickly cause insanity based solely on the extent of the complexity of the command set for git. I probably spent an hour looking through documentation.
The answer was, like you didn’t know where this was going, Google. Ultimately you can the problem with a fairly simple command that WILL AUTOMATICALLY update your config.
git branch --set-upstream yourBranchName origin/yourBranchName
And that is it! Hopefully that saves someone the time that I lost.
Another fix I ran across comes from an initial pull from a remote repository that is empty. Because the original repository (empty) shares no files in common with my local repository (that I have added files to.) Git gets upset. The error generated looks something like this:
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as ‘master’.
fatal: The remote end hung up unexpectedly
It can be fixed with the following command:
git push origin master
Then all remaining pushes should be fine as now you have a shared reference to use for future pushes.