four-eyes
four-eyes

Reputation: 12459

Remote and local repository

I have a remote git repository where I have a remote_branch. I cloned the remote_repository to my machine and created a local_branch.

I now want to push the changes from my local_branch to the remote_branch. Doing that, I set the upstream flag

git branch --set-upstream-to=origin/remote_branch local_branch

I then commit and stage my changes and try to git push the changed on the remote_branch. I get this message:

To [email protected]
! [rejected]        remote_branch -> remote_branch (non-fast-forward)
error: failed to push some refs to '[email protected]'
hint: Updates were rejected because a pushed branch tip is behind its
remote counterpart. If you did not intend to push that branch, you may 
want to specify branches to push or set the 'push.default' 
configuration variable to 'simple', 'current' or 'upstream' to push 
only the current branch.

However, when I push the changed by

 git push origin local_branch:remote_branch

It works. What am I doing wrong?

Upvotes: 0

Views: 52

Answers (1)

C-Otto
C-Otto

Reputation: 5853

On your local machine, you seem to be working on a branch named remote_branch. This branch is automatically created on your local machine when cloning from the remote repository. When you issue git push, the default is to push changes from the current branch. As such, you need to do git checkout local_branch first (and provide the commits there).

In general I'd recommend to use the same names as on the remote repository also locally, and have a 1:1 mapping.

Upvotes: 1

Related Questions