I know this is complicated and probably a stupid question, but here is the situation:
We have a main Git repo with the primary codebase that goes into production. Then we have multiple forks for different people on the team. Occasionally, someone starts working on a change, and it seems easiest for us to add one more small change to their branch on their repo and push that (e.g. if a pull request is already opened and we need to make one small addition). Since we're on the same GitHub team, we can push to others' forks of repos. Right now, we have separate directories for each fork on our local machines for this. But it would nicer if it could just be one directory and we could have multiple forks as remotes.
For example, here is how it might go:
git clone <my fork ssh>
git remote add upstream <main repo ssh>
git remote add teammate <teammate's repo ssh>
git checkout teammate/branchname
After running the last git checkout
, it is in a "detached head" state.
A couple questions related to this are:
- is there a better way to approach this besides having multiple directories for each fork of the primary repo?
- is there any way to get it working as I've intended above?
CodePudding user response:
You can absolutely do this, it's one of Git's big wins. What you fetch or construct or discard in your own repo, and what you call anything in it, is entirely up to you.
git checkout -tb teammate-branchname teammate/branchname
will give you a local branch teammate-branchname
tracking teammate/branchname
.
The histories matter. What you or anyone calls them doesn't. Annotated tags by default and universal convention have the same names everywhere, but even those can be renamed locally.
CodePudding user response:
You can do what you want as follows:
git clone <my fork ssh>
git remote add upstream <main repo ssh>
git remote add teammate <teammate's repo ssh>
git fetch teammate
git checkout -b branchname --track teammate/branchname