Question:
If I am working on two separate projects (repositories stored locally)
~/Documents/git-repositories/fooproject
~/Documents/git-repositories/barproject
and I am pushing to a remote server, how do I switch repositories?
Details:
I am working on my fooproject
. I cd
into the fooproject
directory locally, make changes, git add, commit, and push. The changes all end up in the correct remote repository, fooproject
.
But what if I want to work on barproject
now, a totally different repository? Can I just cd
into the barproject
directory, make changes, git add, commit, and push? Will everything end up in barproject
remotely? Or will it end up in fooproject
, because I haven't made any sort of changes to some git
setting?
Does the answer lie in the .git
file that would change when I cd
into a different repo?
Research and Background:
I think that the way to switch the active repository has something to do with git remote add origin
? I don't know for sure, and I don't want to wreck my repositories by doing something uninformed/foolish. Which is why I came to you guys first!
Repositories in Git are self-contained; the .git
subdirectory in each project contains all the project-specific information such as the default push destination (which is the remote named origin
).
So the answer is: Under normal circumstances changing directories will change where the default push destination goes.
You can check this by using the command:
git remote -v
in each repository to see where origin
points to.