Tagged: Git Toggle Comment Threads | Keyboard Shortcuts

  • Jay Versluis 5:00 pm on December 30, 2012 Permalink | Reply
    Tags: Git   

    Categories: iOS ( 222 )

    How to place an existing Xcode project under Version Control with Git (and ignore files you don’t want to track) 

    Usually when you create a new Xcode Project you can choose to setup a new Git repository. This is the best and easiest way to track your changes. However if you have a project that is not under version control you can create a Git repository retrospectively.

    This is fairly straightforward using the Terminal app on your Mac (under Applications / Utilities):

    • cd into the directory where your project resides
    • then initialize an empty repository (git init)
    • and add the entire directory to it (git add .)
    • commit your changes (git commit -m “initial commit)

    So far so good. However Mac has a hidden directory called .DS_Store in every directory – we may not want to track that. Plus, every time you make a minor UI change in Xcode (such as open a group in the file explorer or something that is not relevant to your actual code) Xcode tracks this change in a file called UserInterfaceState.xcuserstate, and we definitely do NOT want to track that.

    To tell Git that we don’t want those two things, we’ll amend our previous instructions a bit:

    • cd into the directory where you project resides
    • create a file called .gitignore
    • add each file or directory on a new line
    • then create, add and commit your files to Git

    Let’s assume my project is called MyProject, then the steps are as follows:

    cd MyProject
    vi .gitignore
    
    (add the following lines to that file)
    # ignore these files
    .DS_Store
    MyProject.xcodeproj/project.xcworkspace/xcuserdata/myusername.xcuserdatad/UserInterfaceState.xcuserstate
    (save and exit vi by pressing SHIFT-Z-Z)
    
    git init
    git add .
    git commit -m "initial commit, omitting several files"
    

    If you have already committed all your files and forgot to setup the .gitignore file you must manually remove the files/directories you don’t want from being tracked. This is how you’d do that:

    git rm --cached .DS_Store
    git rm --cached # ignore these files
    .DS_Store
    MyProject.xcodeproj/project.xcworkspace/xcuserdata/myusername.xcuserdatad/UserInterfaceState.xcuserstate
    git commit -m "removing files I no longer want"
    

    Replace myusername with your own system user name obviously, and MyProject with the actual folder in which your project resides.





     
    • Jay Versluis 1:58 pm on March 4, 2013 Permalink | Reply

      I’ve just forked a superb general .gitignore for all Xcode projects, courtesy of @adamgit.

      – Copy and paste into an empty .gitignore
      – then initialize, add all and commit

      get .gitignore here

    • Arik Segal 5:13 am on September 10, 2015 Permalink | Reply

      Well done! this is a very useful post.
      One question though:
      Isn’t the derived data folder stored separately in ~/Library/Developer/Xcode/ ?
      If so, it would not be included in GIT commits anyway, so why adding it to .gitignore?

      • Jay Versluis 8:44 am on September 10, 2015 Permalink | Reply

        Hi Arik, I must pass I’m afraid – perhaps this is a question for @adamgit whom I’ve forked the gist from. I was mainly concerned with the interface state since it’s system dependant: if were to I checkout my project on a different system, the interface state doesn’t necessarily look great with another screen resolution. The gist helped prevent confusing Xcode on another system.

        Mind you, that was 2 years ago – perhaps Apple have started fixing things by now (we live in hope) 🙂

  • Jay Versluis 11:00 am on December 30, 2012 Permalink | Reply
    Tags: Git   

    Categories: iOS ( 222 )

    How to place an existing Xcode project under Version Control with Git (and ignore files you don’t want to track) 

    Usually when you create a new Xcode Project you can choose to setup a new Git repository. This is the best and easiest way to track your changes. However if you have a project that is not under version control you can create a Git repository retrospectively.

    This is fairly straightforward using the Terminal app on your Mac (under Applications / Utilities):

    • cd into the directory where your project resides
    • then initialize an empty repository (git init)
    • and add the entire directory to it (git add .)
    • commit your changes (git commit -m “initial commit)

    So far so good. However Mac has a hidden directory called .DS_Store in every directory – we may not want to track that. Plus, every time you make a minor UI change in Xcode (such as open a group in the file explorer or something that is not relevant to your actual code) Xcode tracks this change in a file called UserInterfaceState.xcuserstate, and we definitely do NOT want to track that.

    To tell Git that we don’t want those two things, we’ll amend our previous instructions a bit:

    • cd into the directory where you project resides
    • create a file called .gitignore
    • add each file or directory on a new line
    • then create, add and commit your files to Git

    Let’s assume my project is called MyProject, then the steps are as follows:

    cd MyProject
    vi .gitignore
    
    (add the following lines to that file)
    # ignore these files
    .DS_Store
    MyProject.xcodeproj/project.xcworkspace/xcuserdata/myusername.xcuserdatad/UserInterfaceState.xcuserstate
    (save and exit vi by pressing SHIFT-Z-Z)
    
    git init
    git add .
    git commit -m "initial commit, omitting several files"
    

    If you have already committed all your files and forgot to setup the .gitignore file you must manually remove the files/directories you don’t want from being tracked. This is how you’d do that:

    git rm --cached .DS_Store
    git rm --cached # ignore these files
    .DS_Store
    MyProject.xcodeproj/project.xcworkspace/xcuserdata/myusername.xcuserdatad/UserInterfaceState.xcuserstate
    git commit -m "removing files I no longer want"
    

    Replace myusername with your own system user name obviously, and MyProject with the actual folder in which your project resides.





     
  • Jay Versluis 4:07 pm on December 23, 2012 Permalink | Reply
    Tags: , Git, ,   

    Categories: How To ( 30 )

    How to use Xcode with a remote Git server 

    Xcode_iconImagine you’ve created a project in Xcode with a local Git repository. Now you’d like to put this online so that others can collaborate with you. How do you do that?

    This has been puzzling me for a while, and there doesn’t seem to be a clear documentation on this subject – so I’ve decided to take some notes as I figured it out. Here are step by step instructions on how to make it work.

    All we need is a server running Git and SSH credentials to that server to get started.

    (More …)





     
    • Jaro 12:56 pm on April 2, 2013 Permalink | Reply

      But what if I dont wish to make a new bare repository. Instead I wish to use the local .git file that is here: /%PROJECT FOLDER%/.git ?

      • Jay Versluis 2:16 pm on April 2, 2013 Permalink | Reply

        Hi Jaro,

        In that case, just head over to the Xcode Repository browser (in the Organizer) and click the little plus icon on the bottom left. You can add a local repository there.

  • Jay Versluis 2:27 pm on December 23, 2012 Permalink | Reply
    Tags: Git,   

    Categories: How To, Linux ( 30 )

    How to install Git on CentOS 

    Git-Logo-2ColorGit is a superb version control system that’s tightly integrated into Apple’s Xcode. To collaborate with some coding buddies of mine we wanted to setup a central remote storage on my Plesk server so we could all contribute to the code.

    Since we did not want to share our code with the public we wanted to make it secure. So secure in fact that we could contribute from coffee shops around the world, hence we decided to use Git with SSH. This is probably the easiest and most straightforward way for read/write access to Git remotes: no daemon to setup, to Firewall to tweak – all we needed was a set of SSH credentials and a server running Git with a bit of space.

    (More …)





     
  • Jay Versluis 5:43 pm on August 8, 2012 Permalink | Reply
    Tags: Git, subversion   

    Categories: iOS ( 222 )

    How to add version control to an existing project in Xcode 

    Setting up a local GIT repository:

    Open Terminal and change to the directory where your project is located (cd /path/to/your/project). Then use the following shell commands:

    git init
    git add .
    git commit -m "my initial commit (or any other comment you feel like)"
    

    NOTE: as of Mountain Lion you need to install the Xcode Command Line Tools for this to work (under Xcode Preferences – Downlaods – Components).

    Setting up a local SUBVERSION repository:

    Subversion cannot place an existing directory under version control. Instead you need to create a new directory which serves as the subversion repository. You then checkout a working copy from this repository, work with it and then commit your changes back to the repository.

    • Open Terminal and and create a new directory to hold your repository (i.e. mkdir repos)
    • inside this directory create three sub-directories called trunk, tags and branches (i.e. repos/trunk, repos/branches, repos/tags)
    • copy your existing Xcode project into the trunk folder
    • enter ‘svnadmin create’ inside your main repository directory (i.e. in repos)
    • enter ‘svn import’

    NOTE: Subversion has one extreme drawback: it sucks. Again for any of this to work in Mountain Lion you need to install the Xcode Command Line Tools (under Xcode Preferences – Downlaods – Components).





     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel