Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't push local changes to an existing remote branch

There is a remote branch called "my-remote" that I had previously pushed to with no problem. As of today, I can't push and I get different errors.

First error I got was:

hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. If you did not intend to push that branch, you may want to
hint: specify branches to push or set the 'push.default' configuration
hint: variable to 'current' or 'upstream' to push only the current branch.

I did some research and ran this hoping it would solve the problem:

git config push.default tracking

after running that I ran the push again:

git push https://github.com/someurl/mybranch.git

I got the following error:

pushing to remote 'https://github.com/someurl/mybranch.git', which is not the upstream of
your current branch 'my-remote', without telling me what to push
to update which remote branch.

I have tried running this:

git push master:my-remote https://github.com/someurl/mybranch.git

but it tells me that:

fatal: remote part of refspec is not a valid name in https://github.com/someurl/mybranch.git
like image 721
user1404536 Avatar asked Sep 09 '12 18:09

user1404536


People also ask

How do I push changes to an existing remote branch?

Push a new Git branch to a remote repo Clone the remote Git repo locally. Create a new branch with the branch, switch or checkout commands. Perform a git push with the –set-upstream option to set the remote repo for the new branch. Continue to perform Git commits locally on the new branch.

How do I push to an existing branch?

To push the branch or you can say to push the changes in the branch to the Github repo you have to run this command “git push origin <the branch name>” in our case the branch name is “main”. After pushing the changes the repo will look like and this is how you can push a branch to a remotely hosted GitHub repository.

How do I push changes from local branch to remote branch in Visual Studio?

Here's how to push to a remote in Visual Studio. Make sure you've got a file open to work on that's in a previously created or cloned repo. Make a change to the file, save it, select the Git Changes tab, and then commit the change.


1 Answers

If you want to push your master branch on the my-remote remote branch, the correct syntax would be:

 git push https://github.com/someurl/mybranch.git master:my-remote 

(first: remote repo reference, the refspec, from git push man page)

Regarding your first error message, if it really didn't tell you to merge, then a git pull --rebase might have been needed.
Or at least a:

 git config --global push.default current

(As mentioned in "Configure Git to Only Push Current Branch").

If you are in the local branch 'my-remote' (which is the case, according to the command), you can make sure the upstream branch is set by making a:

git push -u https://github.com/someurl/mybranch.git my-remote:my-remote
like image 93
VonC Avatar answered Sep 21 '22 00:09

VonC