41

This is a two part question: 1) I have added committed and pushed all pod files to github. Is there a way I can remove them and not push them again to github?

2) I know gitignore can help, but I don't know how to use it. Can anyone please walk me through the process of using gitignore?

so I think what I can do is, get the project from github, add gitignore, and then push again. is that correct?

Please help, new to github & Xcode.

skypirate
  • 663
  • 1
  • 7
  • 13

3 Answers3

141

That's correct, you need to add the Pods directory to your .gitignore

1) Remove your files from your github repository:

git rm -r Pods/

and don't forget to commit and push

2) Create a gitignore file:

  1. Open terminal and go through your project folder where the .git folder is located
  2. Type touch .gitignore
  3. Type echo "Pods/" > .gitignore

3) (Added from Gabriel's comment) Last step, remove them from the remote:

git rm -r --cache Pods/

More informations : here

Gabriel Goncalves
  • 5,132
  • 3
  • 25
  • 34
Maximelc
  • 2,384
  • 1
  • 21
  • 17
22

This is what Cocoapods official documentation has to say.

Whether or not you check in your Pods folder is up to you, as workflows vary from project to project.
It recommends that you keep the Pods directory under source control, and don't add it to your .gitignore. But ultimately this decision is up to you:

Benefits of checking in the Pods directory:

  1. After cloning the repo, the project can immediately build and run, even without having CocoaPods installed on the machine. There is no need to run pod install, and no Internet connection is necessary.
  2. The Pod artifacts (code/libraries) are always available, even if the source of a Pod (e.g. GitHub) were to go down.
  3. The Pod artifacts are guaranteed to be identical to those in the original installation after cloning the repo.

Benefits of ignoring the Pods directory:

1.The source control repo will be smaller and take up less space. As long as the sources (e.g. GitHub) for all Pods are available, CocoaPods is generally able to recreate the same installation. (Technically there is no guarantee that running pod install will fetch and recreate identical artifacts when not using a commit SHA in the Podfile. This is especially true when using zip files in the Podfile.)

2.There won't be any conflicts to deal with when performing source control operations, such as merging branches with different Pod versions.

Whether or not you check in the Pods directory, the Podfile and Podfile.lock should always be kept under version control.

Reference Link:Cocoapods Official Documentation

Rishabh Saxena
  • 274
  • 2
  • 6
  • 8
    I might add to the Benefits of ignoring the Pods directory: Some pods are larger than 100MB authorized by github, which will cause error pushing your code to the repository – kernelpanic Oct 19 '18 at 11:15
  • Along this line, I was unable to push my Pods folder due to > 100mb .framework files. The only way I was able to fix the problem was the method given here: https://inteist.com/git-remove-pods-folder-from-pushed-repository-how-to/ – jbm Nov 29 '18 at 23:38
3

Things to give attention when you add /Pods into .gitignore

If you are working in a team, your teammates may face issues while installing pods in their machines and the most likely reason is Podfile.lock.

In summary, Podfile.lock makes sure you don't accidentally upgrade the libraries you pull in while keeping your Podfile concerned only with the new dependencies.

Why Podfile.lock may cause problems?

Podfile.lock locks the project with versions installed the first time and when you execute pod install again, this will only install any new library in Podfile and will not affect your existing libraries by updating them to latest code.

In case of pulling repo does not contain /Pods, Podfile.lock locks versions of pods that do not exist in your machine because of .gitignore and expecting that these libraries are existing.

Easy solution to go with

Just remove Podfile.lock then execute pod install and Podfile.lock will be generated again with versions of pods you installed.

Note: After removing Podfile.lock and installing the pods, you may interact with different versions of pods than your team.

Essam Fahmi
  • 1,920
  • 24
  • 31