Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Git with an existing Xcode project

Tags:

git

xcode

People also ask

How do I add a Git repository to my existing Xcode?

Push your projectGo to Source Control in Xcode and select Projectname -- master, then Configure... In the Address field, paste the Git clone URL for your repo copied in the previous step. Select Add Remote, then select Done to finish creating the origin remote for your local Git repo.

Does Xcode work with Git?

When you create an Xcode project for the first time you can create Git Repository on your mac. But this step can also be done after creating your project by navigating to your bar items and going to “Source Control” then clicking on “Create Git Repositories…”.

How do I add an existing IOS project to GitHub?

for xcode 9, just go to the source control tab in the navigation inspector in Xcode. right click on the master git and select create "Your project name" remote on GitHub. give your GitHub credentials and give a name to git repo and Xcode will create and push your code for you.


GitHub has some very good git tutorials at help.github.com.

to do the initial setup of a repository, open up a terminal window, and CD to the project directory. once there, type

git init
git add .
git commit -m "Initial commit"

Restart Xcode. The repository should now be set up, and you will be able to manage it in xcode 4.


Xcode 7 (and 8)

If you were starting a new project you would just check Create Git repository during the setup. (Then skip down to the Commit part below.)

enter image description here

But it you are working with an existing project, go to Xcode > Preferences... > Source Control and check the Enable Source Control box.

enter image description here

Then in the main Source Control menu choose Create Working Copy....

enter image description here

(If you get a "Please tell me who you are" error the see this question/answer or one of the other linked questions there.)

When that has finished, make any change to one of your Xcode project files. Then go back to the Source Control menu and choose Commit.

enter image description here

And write a commit message and click the Commit button. (If the commit button is disabled, then make any minor change to your project and try again.)

enter image description here

In Github sign in and create a new repository.

enter image description here

Call it whatever you want, but don't add a README or .gitignore or license yet. You can add those things later. Doing so now will make the syncing more difficult.

enter image description here

Copy the link to your repository.

enter image description here

Go to Source Control > your branch name > Configure.

enter image description here

Click the Remotes tab > "+" button > Add remote....

enter image description here

Enter the github repository name and paste in the address.

enter image description here

After adding the remote, click Push in the Source Control menu. Enter your github user name and password. That's it. You project should be copied to github now.

(I had some trouble getting my username and password accepted at first. If that happens to you go to Xcode > Preferences... > Accounts > your new repository. Enter your user name and password there and then try the Push again.)

enter image description here

You can add a README and other files, but if you do it from the web, you will have to do Source Control > Pull in Xcode before you con commit other changes.

Now any time you make changes in Xcode, all you have to do is Commit and Push.

I learned this method mostly from here.

See also

  • The Basics of Git and GitHub
  • How to add a .gitignore file for Swift in Xcode

I just went through the process of doing this for several projects, and ran into some issues. Here was my process, mostly pieced together from the other answers on this page/site. Order is very important here

  1. Open terminal and cd into the directory containing the .xcodeproj file
  2. git init
  3. In finder enter the newly created .git folder (in the same directory as the .xcodeproj file). Find info/exclude, open and add these lines, .DS_Store and xcuserdata/
  4. Not sure if this is needed, but I used terminal to cp info/exclude over to a .gitignore file
  5. git add .
  6. git commit -m "Initial commit"
  7. Now to get XCode to actually see the repo. In the project organizer, you first have to delete the project from the Projects tab. Then simply re-open the project to get it back. This will detect the GIT repository just created
  8. In the repositories tab of the organizer I then branch off the master branch/switch into whatever version I'm working on.

Hopefully this helps someone without being too redundant. What now seems simple was definitely a challenge for someone new to GIT with existing projects


Check out my post on this topic Setting up a git repository in XCode for a pre-existing project. The above is correct, but it will include UserInterfaceState in your changes as you commit and this could be annoying because this file updates everytime you do anything in xcode, even if it is as simple and navigating through files or folders in your project.


if your XCODE 7 is not connecting with existing GIT repository. Try following

xcrun git config --global user.email [email protected]
xcrun git config --global user.name "your name"