git clone and remote dependency

Viewed 75

I have my own python project (local to my laptop and no git init) and I want to use some module of capirca (https://github.com/google/capirca.git) so what i did was:

I want now to create some function inside folder Capirca/ but as soon i modify anything the modified file appear in my source-control section ready to be committed (visual-studio)

(vend) ➜  capirca git:(master) git remote -v                                      
origin  https://github.com/google/capirca.git (fetch)
origin  https://github.com/google/capirca.git (push)

I tried to delete the git origin

(venv) ➜  capirca git:(master) git remote rm origin                                   
(venv) ➜  capirca git:(master) git remote -v           

but still, the file that i create appear in my source control (visual studio code) as ready to be committed. This is valid for anything inside folder capirca.

What am i missing here?

1 Answers

It is the expected behavior that any changes you make in a git repository, it will be picked up by git.

If you don't want this to happen, simply delete the .git folder inside the newly cloned repository. This will imply that you won't be able to pull any latest changes in your dependency, hence not a recommended approach.

Else if you want your folder to be tracked by git and the new project be ignored, you need to create a .gitignore file in the root of your project and add the folder you want to ignore.

The most ideal approach is to use a submodule.

$ git submodule add https://github.com/org/repo

Any further changes in the dependency / submodule should be made in a separate branch, ideally, you can fork the dependency in your GitHub, essentially allowing you to commit your changes in your dependency as well as allowing you to pull-in any additional bug-fix or features in the mainline.

Detailed explanation for submodule here: https://git-scm.com/book/en/v2/Git-Tools-Submodules

Related