Monday, April 13, 2015

GIT : getting the lastest changes from your upstream master when you have no changes in your repo

I clone a lot of our micro service repositories locally into my own branch, but then really don't add to them. A few months pass and then I need to re-sync.

GIT seems to make it a little harder to do it compared, to say, Perforce, another source control program. At a high level you have to get the latest changes from your upstream master, that you forked from earlier, fetch and then merge.

I've detailed the more individual steps below, and what I encountered. To start, you may not even have your upstream master defined!

Here are the high level command line steps I took on my Mac Book Pro.

git fetch upstream

   I got > fatal: 'upstream' does not appear to be a git repository. So here upstream is not defined.

git remote -v

   With this command I noted that no upstream was listed. Guess I have to create it then.

git remote add upstream http://github[remainder of URI path]/[repository name].git

   This command allowed me to define my upstream 

git remote -v

   Verification step that upstream remote was now defined

git fetch upstream

   This got me the latest changes, but stored it locally in a repo called upstream/master.

git log

   This verified that the latest changes - in my local master repo - were still from a few months ago so a couple more steps needed.

git checkout master

   Although not needed in my case, just a verification I was on the right branch. This command will move you to the master branch in case you might be on another branch.

git merge upstream/master

   This command finally synced my local unchanged branch to the latest changes in the HEAD, aka upstream.

git log

   With git log I saw the latest changes were from today.


Hope this helps.

No comments:

Exploring ELK (Elastic) Stack for hack-a-thon

At my current gig, our group finally got to do hack-a-thon week and I joined a team project that tied together a few of the technologies I&#...