Xcode 5 - How to use source control with a workspace - xcode

I've created myself a Xcode 5 workspace and added 2 projects into it. The first project is a Mac OS X Cocoa Application and the second is an External Build System.
When creating the projects I checked the option so it would create a git repository for each. Then, I've tried looking at the menu item Source Control and every sub item was grayed out except Check Out ... which is not what I want to do. I wish to add the files to the repo.
How can use source control in Xcode 5 with a workspace?
Edit: I've tried to create the projects without the git source control option and creating the git repositories manually from the Terminal. Sadly, Xcode is not detecting them.

Finally, I've found a solution to my problem.
I created the workspace with the projects inside without any source control options. Then, I manually created a single git repo inside my source folder by doing the following in the Terminal.
cd /path-to-my-source-code/.git
git init
git add .
After, I added a .gitignore file inside the .git folder as suggested in https://stackoverflow.com/a/12021580/209824.
The final step was to restart Xcode.

Related

add Xcode target in git repository

I am working on an iOS project.
I have checked source control support (git) at project creation.
I have add a target for apple watch. In fact Xcode created 2 targets: watch app and watch app extension.
My problem is i was supposed to see a letter (A) in project tree but i do not see nothing next to new files.
How can i add those new folders and files in git ?
Thanks
git add -A
This command will add all new changes in the current repository. To run it just open Terminal and go to your Xcode project folder and type it in. You can then see the added changes with git status

Xcode source control issue (All projects are already under source control)

The last 5 or 10 sessions, whenever I go to start source control (Source Control > Create Working Copy), I'm prompted by a message "All projects are already under source control." For each of these projects that this message popped up on, I went to the directory of the session in Terminal and ran ls -a to check for hidden files and see if .git files really existed. I did this in the directory the Xcode sessions are located and went back one folder at a time, checking each folder for .git files as well, but none of the parent directories have .git files either. The only way I can get Xcode to start source control is if I use terminal to make the first git commit:
git init git add . git commit -m "Initial Commit." This never used to happen before, I used to always be able to start source control through Xcode.
Then I can use Xcode source control after.
Anyone know of a fix?
On OS 10.12.3 and Xcode 8.2.1
I wrote a solve in the form of articles at a similar issue.
https://stackoverflow.com/a/50751648/2036103
hope will help someone.
The message All projects are already under source control, means the project has already controled by git (.git folder in the same path or as the parent path of the). So what you need to do for the project in xcode is to commit/pull/push. Or you can config the project by source control -> project (usually above create working copy item) -> configure git.
If you want add a file in the same git repo, you should add a file in the path same as .git or it's sub-path, then in xcode -> source control -> commit -> select the file you added -> commit.
If you want to do source control for another project, you should close the current project, and then reopen xcode with another project.

Xcode won't add files to source control

when ever i add files to my project. Xcode should automatically "at least it did at one point" add it to my source control. and write a A out for it.
now it just does this : see picture
i tried to reinstall Xcode using app-cleaner.. nothing changed there
And NO it doesn't help if i click the add files, no matter where in Xcode i click Add - nothing happens...
i'm using Github as repo
and using Xcode 5.1
i know i could just use Terminal and use git commands like : git add -A git commit -m "first init" and finally git push origin -u
but Xcode should do all this for me
If you click on 'Source Control' in the XCode menu do you see two options listed? I found that I had a .git file located in my iOS projects directory which contains all of my iOS projects. I deleted this and it fixed the problem.
I think that when you import all of your repos into SourceTree it creates a .git file in the parent folder of your repos.

in Xcode 4 how to associate a project to the local Git repository I set up?

in Xcode 4 how to associate a project to the local Git repository I set up?
That is:
I've set up a Git repository after the Xcode 4 project was already created, based on instructions here:
I've gone to Organizer and "added" this as a local Git repository
When I go to my project in Xcode 4 the source code functions still don't appear to work - I'm guessing it because there must be some way of tying the Xcode Project wiht the local repository I created?
From "How to Create Git Repos for Existing Xcode Projects":
UPDATE: Apparently just initializing an empty repository in the project directory is enough; Xcode autodetects it for you.
It be nice if something to that effect was in the documentation. Thanks to Jason for that (details here). Open the project directory in a terminal and type the following:
git init
git add .
git commit -m "Initial commit"
So in your case, it should detect it.
The OP Greg comments:
I found out that all I had to do was change a file, and then the Xcode 4 pop up menu for the file did show a source control set of options (previously greyed out).
So the initial part of the answer is correct re the manual git commands for creating the git repository.
Otherwise you can try:
make a new XCode4 project with a(n empty) git repo in it
move your .git directory and override the Xcode 4 project .git
move the sources in that new Xcode 4 project directory
see if XCode4 then detect your sources and the Git integration
Not your case probably, but one of the comments mentions:
If you're switching from an SVN repository (which I was), the trick is to go into your project folder and delete or rename the .svn directory.
For me it seemed that Xcode would find the .svn folder first (or preferred it, even though the backing repository was decommissioned), but once it was gone Xcode would happily start using the git repository.
That was actually the issue for another Xcode 4 Git user here on SO.

Convert Xcode project to New Xcode 4 with Git and enable .gitignore?

I'm sort of stumbling around with an issue with Xcode 4, and Git. I'm a one man shop with multiple macs, and had my project working with Git and Xcode4, (stored on a dropbox folder), so I could share that folder across my MBP and iMac with minimal interaction. So, it was late one night and I accidentally committed my xcode project file, and then I started getting issues with UserInterfaceState.xuserstate constantly updating... Later learned that .gitignore would have been good to have in place.
Back to the drawing board and I've been trying to take the new (old) project and enable git on it with the following:
$cd path/to/project
$git init
$git add .
$git commit -m "Initial commit of project"
This works fine, now I'm back in XCODE, and add the repository, which it recognizes in Organizer. One Issue is XCODE doesn't recognize that I've modified a file, and the majority of the "Source Control" menu items are disabled, Ex: "Commit"
I'm wondering if there are a recommended # of steps to:
1) Get Git running on a xcode project that wasn't set up this way initially
2) Steps to add the Gitignore file and when
Ultimately would like the "Source Control" menu items enabled again.
I'm obviously learning some Git SCM related items with xcode 4, and I appreciate your feedback!
Maybe this isn't the answer you want but I gave up on getting Xcode4 to play well with git and just started using the excellent (and free) SourceTree. It really made my life easier.
To add Git to the project
Go to the directory and in a terminal window
cat > .gitignore
build/*
*.pbxuser
*.perspectivev3
*.mode1v3
javascripts/phonegap.*.js
Type Ctrl+D to close the file.
Initialize the Git repository
git init
git add .
git commit -m
Add the repository in organizer. Use the full directory path.
Caveat - this still does not enable Source Control menu items. But you can use git from the command line.
See other related post: Using Git with an existing XCode project
There are three ways of setting up exclude files in git. Which is easiest depends on you. But, I find that when using git to share for myself amongst multiple machines, a global ignore file works best, and I can always add more specific excludes if you need to.
Essentially
Globally, by setting up a per user or per machine exclude file
Per repository - by setting up a .gitignore file in the repo
Per clone - by setting up the `.git/info/excludes file
I've got a my global exclude file on Github if you want to see an example, including Xcode4 specific exclusions.

Resources