Reputation: 8423
Suppose I have a Git repo and it has a name — old_repo
— and a remote origin old_remote
.
Now, I want to create a new repo with a name — new_repo
– and I want to change its remote origin to the brand new new_remote
.
I also want to make it possible to update the new_repo
if there are any updates to the old_repo
(but not the other way round), but I don't want the new_repo
to be a fork of the old_repo
.
What would be the best way to do that?
I'm thinking about this:
mkdir /path/to/new_repo
cd /path/to/new_repo
git --bare init
// the new_repo it's accessible via ssh://my_host/new_remote
// now I want the branch master to be accessible as the branch master in the new one
cd /path/to/old_repo
git push ssh://my_host/new_repo +master:master
cd /path/to/new_repo
git clone ssh://my_host/new_repo
However, in the case above, how would I be able to get updates from the old_repo
into the new_repo
if needed?
Upvotes: 0
Views: 161
Reputation: 10750
You would set old_repo as an upstream, and then you could pull from it:
git remote add upstream /path/to/old/repo
Then, to get updates from the old repository, you can pull from upstream:
git pull upstream
Side note: Instead of doing all that stuff with cloning old repo, you could just copy it to a new location and then change the origin:
cp /path/to/old/repo /path/to/new/repo
cd /path/to/new/repo
git remote set origin <new remote location>
git remote add upstream <old remote location>
Then, whenever you need to fetch updates you can just run git pull upstream
(or git fetch upstream
if you want to inspect them before merging)
Upvotes: 2