Success – git mysteries on Apple resolved (finally!)

Today I finally achieved success performing the desired git merge on my GasRad project on my Macbook. As mentioned previously, GasRad is my SCUBA gas blending app written for IOS devices (iPhone, iPad) using Xcode on my Macbook.

When we last looked in, I had a branch ‘alt_testing…’ many commits removed from the master branch. As hard as I tried, I could not figure out how to merge the ‘alt’ branch back to master using either Xcode or SourceTree on the Mac.

I spent the last two days, and yesterday in particular, tackling this problem. First I made sure that my Xcode project was backed up using the mac time machine program. This was critical as it turned out. <hint: Always back up your work before  doing ‘stuff’. ALWAYS>. With the project backed up, I tried various means and methods to merge master with ‘alt’. I read and re-read the Pro GIT PDF book, and checked many solutions on-line (again, thanks Stack Exchange).

Ultimately, it was one problem that kept things from working: Xcode changed the way it tracked changes to Xcode; new versions of .gitignore handled this, but older versions didn’t. The result was every time I switched to master in Xcode, it wanted to store (commit) the UI change file. Over and over and over. Kind of a catch-22.

After messing about during  the day, I finally had an epiphany late last night. Actually, TWO.

  1. My project was not really branched at all. I had created a branch ‘alt’ back in May 2014, and had many commits on that branch, but absolutely zero commits on master. Really, it was just a simple linear series of commits, and only  the branch ‘name’ was different. As it turned out by my experimentation during the day, the actual merge was simple (no conflicts) if ONLY I could solve the problem of the persistent UI commit when in the master branch.
  2. Other testing during the day showed using terminal to issue git commands worked perfectly on the Mac, and did not conflict at all with either Xcode’s implementation of git, nor with SourceTree’s. The epiphany was that if I started with the ‘alt’ branch with Xcode not running, I could switch to master using terminal git commands and not involve the UI file at all.

Knowing these two things, this morning I set about my final cunning plan. I made sure the ‘alt’ branch was fully committed and working. I then terminated Xcode and SourceTree. I started up terminal, moved to the GasRad directory, and typed ‘git checkout master’. This switches to the master branch. Then “git merge alt…” which quickly and cleanly merged ‘alt’ into master. Using SourceTree I confirmed that master and ‘alt’ were now the same. I used SourceTree to tag the old master location as V2.0.0 and the new master location as V2.0.1, just to remind me where these branches had been. Finally I removed the ‘alt’ branch as it was now the same as master. The result was/is a clean branch tree with only the master branch, fully committed. Of course I finished up by using time machine to back up this clean version.

The real secret here was using terminal to bypass quirks in Xcode due to having git branches that spanned a major IOS/Xcode upgrade. Lesson learned is to ensure any git project is where I want it to be BEFORE I upgrade IOS or Xcode. I also learned the real value of SourceTree is in it’s graphical view of the project’s git history, and it’s ability to easily add tags to any commit.

I am a much, much happier Apple camper today.

Comments are closed.