This is how I did it: (Some commands can of course also be done via the file manager or in the Git GUI, e.g. Sublime Merge allows adding remotes via menus)
First, I clone the repo, and reinitialize a fresh git repo:
git clone https://github.com/someoneelse/theirrepo.git
mv theirrepo mylocalrepo # I want another name
cd mylocalrepo
rm --recursive --force .git # delete the .git folder
git init
git add --all
git commit --message 'Fresh start'
Next, I create a repo myexternalrepo
on, for example, Codeberg.
Then I connect myexternalrepo/master
to mylocalrepo/master
:
git remote add myexternalrepo https://codeberg.org/me/myexternalrepo.git
git fetch myexternalrepo
git push myexternalrepo master --set-upstream # '--force' can help. But use only in private repos.
mylocalrepo/master
is now configured, the pull
/push
button(s) are functional in the Git GUI.
Now I create mylocalrepo/cherries
and connect it to theirrepo/master
:
git remote add theirrepo https://github.com/someoneelse/theirrepo.git
git fetch --no-tags theirrepo master # This time I need just the master and no tags.
git checkout -b cherries theirrepo/master
The last thing to do, is to configure, that the pull button of the GUI, when in the cherries
branch, only fetches the master branch of theirrepo
, and also ignores the tags. These things make it more difficult to find my own branches and tags. So I make the following changes to the [remote "theirrepo"]
section in .git/config
.
To fetch only the master branch, I replace this refspec:
fetch = +refs/heads/*:refs/remotes/theirrepo/*
... with ...
fetch = +refs/heads/master:refs/remotes/theirrepo/master
To prevent that the tags are fetched, I add:
fetch = ^refs/tags/*
tagOpt = --no-tags
The fetch = ^refs/tags/*
is a negative refspec blocking all tags. It is a workaround for the fact that setting tagOpt = --no-tags
alone seems not to prevent tag fetching, which seems to be a bug in git or in its documentation, see this related question.
Now everything is configured, when on master
, pulling/pushing will communicate with myexternalrepo
, and when in cherries
, pulling will communicate with theirrepo
(pushing will refuse to work).