0

I ran into some issues when creating my Xcode project that really screwed up the Git repository. It had references to the build folder and a bunch of other files I didn't want in there. It's a fairly new project so discarding past commits is fine. Therefore I removed the .git folder.

I've since then gone back into Xcode and Source Control/Create Git Repositories. I create a repository for my project from there.

However none of my files are able to be committed as they obviously have not changed but I need to do an Initial Commit.

I've seen many other posts about this where they state to use "git add ." However this would then result in a bunch of files from my project and Build/ folder being committed as well as my Pods folder which I do not want to do. Committing the project files into the repository I know is a big no no. However I'm uncertain which files or folders to ignore.

Is there a way to get Xcode to create the repository as it does when you first create the project? Or does someone know which project files should be committed and which ones should NOT be committed so I can create some .gitignore files in the project package to clear all that up?

1 Answer 1

2

1) First in order to make git ignore certain files you will need .gitignore file here is one for Swift or Objective-C add it to your repository folder.

2) then you need to remove all committed files use this command in terminal after changing directory to repository folder

git rm -r --cached . 

3) then add all files by using this command in terminal

git add .

4) and add the initial commit

git commit -am "initial commit"

if you didn't initialize git after removing .git folder skip step 2

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, this looks like it's going to work. That .gitignore file you pointed me to helped! One question I have though, should I be committing the .gitignore as well?
It depends - If you think .gitignore could be helpful for anybody working with the repo then commit. If you have any sensitive files in .gitignore which you don't want to share then put them in $GIT_DIR/info/exclude

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.