I want to change the Git default remote branch destination so I could just
git push
Instead of:
git push upstream
If you did git push origin -u localBranchName:remoteBranchName
and on sequentially git push
commands, you get errors that then origin doesn't exist, then follow these steps:
git remote -v
Check if there is any remote that I don't care.
Delete them with git remote remove 'name'
git config --edit
Look for possible signs of a old/non-existent remote.
Look for pushdefault
:
[remote]
pushdefault = oldremote
Update oldremote
value and save.
git push
should work now.
In my case, I fixed by the following:
* run git config --edit
* In the git config file:
[branch "master"]
remote = origin # <--- change the default origin here
Very simply, and cobbling together some of the great comments here along with my own research into this.
First, check out the local branch you want to tie to your remote branch:
git checkout mybranch
Next:
git branch -u origin/mybranch
where:
git branch -u {remote name}/{branch name}
You should get a message:
"Branch mybranch set up to track remote branch mybranch from origin."
Another technique I just found for solving this (even if I deleted origin first, what appears to be a mistake) is manipulating git config directly:
git config remote.origin.url url-to-my-other-remote
You can easily change default remote for branches all at once simple using this command
git push -u <remote_name> --all