How to add .gitignore file into Xcode project - xcode

When making sure that iPhone project could be installed as an exact copy into a brand new computer via version control (git), I just realized that .gitignore file was missing. Added under version control, but now would like to add that file also into Xcode project for easy viewing and editing.
When using "Control-click + Add Files to myProject..." popup menu, I can't see any filenames starting with . (that's a dot). How can I add my .gitignore file into Xcode project?

When the open panel is showing, press Command-Shift-. and the hidden files will appear, including .gitignore.
Select the .gitignore file and press the Add button.
This works in any app, not just Xcode. It's an obscure feature of NSOpenPanel.

This solution didn't work for me in XCode 8.0 and El Capitan.
I opened a terminal and typed:
defaults write com.apple.finder AppleShowAllFiles YES
cd ../PATH_TO_GIT_ROOT
touch .gitignore
Then relaunched Finder and my .gitignore file was visible. Edit per .gitignore documentation

There are only three lines of code that you should write to terminal in order to achieve updated .gitignore file for Xcode 12+.
First step is setting a global configuration for .gitignore file from Gitignore.io
git config --global alias.ignore '!gi() { curl -L -s https://www.gitignore.io/api/$# ;}; gi'
In the second step go to your project folder then generate the .gitignore file for your project.
git ignore swift,macos >.gitignore
Lastly, commit the generated file.
git commit -m "Add .gitignore file"
You can open the .gitignore file with Text Editor and uncomment any Folder-File that you don't want to commit into your repo.(For example Pods/)

Related

Accidentally deleted .xcodeproj file how to recreate it?

I did a silly mistake and deleted .xcodeproj file from command line. Since it's deleted from command line it's not in bin so it's gone. I've all other files in the project. Is there any way to recreate .xcodeproj file and fix the project?
I'm using local git provided by xCode as default, not sure if it will help?
If you haven't committed the deletion of the file, do the following:
Open Terminal
cd /path/to/my/local/repo
git checkout -- myproject.xcodeproj

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.

Why doesn't Xcode create a .gitignore file?

I'm aware of how to create one and there are lots of posts of what should be in them for an Xcode project. This is a more basic question.
When creating a new Xcode project with the git option why doesn't Xcode create a default .gitignore file?
Assume that I'm just working locally, I haven't created any remotes.
If I don't add a .gitignore myself does that mean that the files that are usually added to a .gitignore (like .DS_Store and *.xcuserdatad for example) are being managed by git? Is this bad?
Or is Xcode doing something behind the scenes to ignore those files?
I'm pretty sure that Xcode does not create a gitignore file on its own. So this is how I start a new project now.
Create a new project in Xcode. Do not create a local git repo. The problem with getting Xcode to create the repo is that it performs an initial commit before a gitignore file is created. I prefer to add gitignore before the initial commit.
Close the project.
In Terminal, navigate to the directory containing the
new project.
git init
curl https://www.gitignore.io/api/xcode > .gitignore There are lots of places to get gitignore files but this is super handy as shown on NSScreencast episode 156.
git add . Be sure to include the dot, that adds everything.
git commit -m “Initial commit."
Open the project in Xcode and inspect the Source Control menu. If you select History you should see the initial commit.
Update:
www.gitignore.io now redirects to www.toptal.com/developers/gitignore
It's nice. You can specify keywords like xcode, cocoapods, etc.

Can't add xCode 4.2 project to repository (and get it working)

I created a new project and all files are added to the projectfile.
I 'cd' to my project root and does the following steps:
rm -rf .git (remove all left overs if any).
git init
git add .
git -m "initial commit"
Then I load my project, and make some changes to my code. xCode 4.2 notifies this correctly by adding the 'm' (modified) icon in the project explorer.
I right click the modified file and choose "Source control->Commit selected files" and it says: The working copy "of my project" could not be found. Please verify that the working copy is reachable and try again.
The entry I just created is red in Organizer, any ideas whats wrong? Have I missed a step?
I suggest using built-in GIT support inside xCode, not a command line git.
On project creation page, where you select folder to store project, there is checkbox you mark if you want to use GIT.
All other GIT stuff are accessible view File->Source Control menu.
So, try re-creating your project but make sure you've selected GIT support.

Remove git from project in Xcode 4

I just created a new project in Xcode 4 and I guess I left the "Create local git repository for this project" box checked. Now, I would like to remove this version control since I want to run the project with svn only. Is this possible or do I have to create a new project from scratch?
I had the same problem. Here are the steps to resolving this.
Go to the Organizer (under window menu option)
Go to Repositories
Look at the bottom left corner for the minus button
Select the project to be removed from GIT
Press the minus icon
It should be removed
This works, even though the class files still have the symbol next to them. Clicking them then clicking another file gets rid of the icon.
Hope this works.
Just remove the .git directory in the project folder. You should close the project in Xcode first to be safe.
If you want to disable Git support in Xcode 4 you'll have to rename "/Developer/Library/Xcode/PrivatePlugIns/IDEGit.ideplugin" to something other than .ideplugin.
I had the same problem. I followed the steps from this blog post and all worked fine for me. I was using Xcode 4.2 on OS X 10.7.3.
I think the trick is making sure to delete the invisible ".git" folder in the project directory via the command line,... in addition to deleting the repositories via the Xcode GUI.
I'm now using SourceTree with Mercurial on BitBucket, and am a very happy camper! :-)
You can easily do that using
rm -rf .git
rm -rf .gitignore
Open Terminal and Type
Terminal
$ cd /RootOfProjectFile
$ rm -rf .git
$ rm -rf .gitignore
Manual Delete
Open Terminal and type
$ defaults write com.apple.finder AppleShowAllFiles TRUE
$ killall Finder
simply open the project in finder delete the .git and .gitignore from root/ (Where project file is present)

Resources