I have a repository on github, say testrepo. Now I'd like to set up a local repository repo
that has one branch origin-master
where I want do be able to edit things from the repository.
repo/origin-master <--------> origin/master
The cloning works fine:
mkdir repo && cd repo && git init
# not necessary of course:
echo "master" > master && git add master && git ci -m "master"
git remote add origin [email protected]:<username>/testrepo.git
git fetch origin
git branch --set-upstream origin-master origin/master
git checkout origin-master
# create a new file:
echo "for origin-master" > orig-master && git add orig-master && git ci -m "orig-master"
but
git push origin
To [email protected]:<username>/testrepo.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:<username>/testrepo.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
How can I tell git that if I want to push to origin, I want to push the local branch origin-master
to origin/master
?
See this post for good advice of pushing to a non-bare (i.e. with working copy) repo. Basically what's going on here is that when you push this way, the remote repo doesn't update it's working copy (the real files), only its history. You then need to git reset --hard
on it to refresh the files, but it's dangerous since you'll lose non committed modifications.
As a general advice I would say to prefer pull to push when dealing with multiple non-bare repositories: push to only bare repositories!
I have problems understanding what kind of workflow you are trying to set up, but would this help?
"How do you make an existing git branch track a remote branch?"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With