I'm using
git clone --bare -b main --single-branch <internal-repo-url> internal
cd internal && git push --mirror <private-fork-url>
To create a private fork of an internal repository. In this way I can pull in updates from the origin repository through another remote that is not 'origin':
git remote add internal <internal-repo-url>
git pull internal main
Is there a way for me to create a bare clone with the 'main' branch under a different name? My motivation for doing this is wanting to have the private fork's own 'main' branch distinguished from the internal repo
CodePudding user response:
The right sequence would be:
git clone --bare -b main --single-branch <internal-repo-url> internal
git remote rename origin internal
git remote add origin <private-fork-url>
git branch -u origin/main
git push --mirror
That way, your local main branch is tied to the upstream private-fork-url/main
, while you still have internal/main
CodePudding user response:
My regular workflow when forking on GitHub is this:
- Use the regular GitHub forking functionality.
- Locally, I check out from my GitHub repository. The
origin
remote then points to my repository (created in step 1) on GitHub. - Configure an additional remote
upstream
to the original repository.
This allows me to use git rebase my-feature-branch upstream/master
in order to incorporate latest changes from there.
That said, keep in mind that there are three similar branches now: main
(local), origin/main
and upstream/main
. Similarly, you can also specify where you push your work when you push and you can pick the target repository, the local reference and the remote branch independently.