Friday, June 27, 2014

Using git Within a Centralized Repo Environment

I have worked at several, less than idea locations, when it comes to using Xcode. What is less than ideal? When they want you to use a central repository that requires online access and which does not integrate with Xcode. 

As an Xcode dev, I want and prefer to use gitAs a dev, I prefer git, so when you take git away from me I get grumpy. 

But I am only grumpy for a short while. We have ways to work around this madness.

Here is how I work around the friction of using a centralized repository like TFS (Team Foundation Server) or Perforce when working on an Xcode based project. 

  1. Check out the latest code from the centralized repository into a clean directory. 
  2. Initialize a local git repo immediately using: git init 
  3. Setup my git ignore file: .gitignore 
  4. Check the entire code base into the local git repo as the first commit. 
  5. Start work like I always do with Xcode. 
    1. Caveat here is that most centralized repositories are going to have all files locked (read-only) on Mac. 
    2. When you go to work with a read-only file in Xcode it is going to prompt you to Unlock the file. Do it, unlock the file and edit away. 
  6. When I am ready to commit my changes I can now see the files I changed from within git. Using that list I go into my centralized repo tool and check out those files for editing. 
  7. Then I make my changelist, changeset (or whatever your version control system calls a set of files for checkin) and submit it to the central repo. 
  8. I then commit my changes locally to git.

Here is how I perform a merge/pull/get latest from the central repo. 
  1. If I have outstanding change not ready to commit then those are on a branch for that work (you use branches in git right?) 
  2. I go to my clean master branch and checkout the latest code from the central repo. 
  3. I then add and commit them within git as a "Central repo merge." 
  4. I then change to my branches and rebase the branch from master. Fix conflicts and continue. 

So, after a bit of grumbling, I have a new process that I can use so that I can continue to use Xcode's built in version control of choice (git) while respecting the projects decision of choice (centralized repo). 

As with many new technologies (if we can call git new) I can not wait for git to win the war and for dev teams to switch over to distributed revision control systems. 

Note: Now for those that may like another distributed revision control like Mecurial, they are great as well. But until Apple opens up Xcode and provides an API or plugin mechanism to let devs plugin their revision control system of choice, I will be a devoted follower of git and it's first-class status within Xcode.


Cem Catikkas said...

Have you checked out git-p4 or git-tfs? They let you use git and pull from/push to p4 or tfs. Good stuff.

Unknown said...

Yes, I used git-p4 a ton in the past. It was great. Git-tfs caused history issues so it was abandoned and we went back to TFS only.