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
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.
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.
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.
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
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