Olivier Pons
Olivier Pons

Reputation: 15816

Git and other git subdirectories

I dont know if my problem is related to github or git or PyCharm...

I have a laptop (L) and a stationary PC 1 (= P1).

I've made a git repo on github, and I've worked a lot on it from my P1. Then commit + push all my work on github.

From L, I did a git clone, and it worked really well.

Now, I've added a new library in my Django static/vendors folder. It's called howler. I got it from here. I've added it using a git clone https://github.com/goldfire/howler.js.git. Same thing with another library called swiper: git clone https://github.com/nolimits4web/swiper.git.

The problem is that PyCharm added the 2 git repositories in the vcs and they're not visible from my 'original' github remote: when I commit + push my work, everything is commited + pushed except those two libraries. From the PyCharm menu, if I do a VCS -> git -> Remotes, I get this:

Git Remotes

So, when I do a git pull from my laptop, it gets everything except those two libraries. What should I do to add those repositories into my github repo, and then being able, from any other PC, to make a git clone then afterwards a git pull, and get those libraries too?

Upvotes: 0

Views: 49

Answers (2)

Jeff Gruenbaum
Jeff Gruenbaum

Reputation: 403

This goes against the purpose of having packages. Best practice is to keep your source code in git, and the packages outside of it. If your source code has a list of required packages needed to run, you will have to install those packages whenever cloning the repo on a new machine.

Instead of using git clone, I would recommend using this command: git submodule add https://github.com/goldfire/howler.js.git howler

Using this submodule will create a .gitmodules file in your repo that will look like this:

[submodule "howler"]
    path = howler
    url = https://github.com/goldfire/howler.js.git

This will let you keep track of all the packages installed and being used in your project.

If you really need these packages in your repo. Delete the .git hidden folders in both the packages and then do a git add, commit, and push to the repo.

Upvotes: 1

gerwin
gerwin

Reputation: 909

Git is being smart about this and treating howler and swiper as not being part of your project, because you have cloned them. It treats it as being a submodule, but you probably don't have the .gitmodules file to handle that. You can do two things:

  1. Use the subtrees as submodules. See docs here: https://git-scm.com/docs/gitmodules

  2. Or, the easy way: remove the .git directories in the howler and swiper subtrees. Then git will not see them as submodules anymore BUT you won't be able to git pull to keep them updated anymore.

Upvotes: 0

Related Questions