git branch --unset-upstream
This command is useful when you want to disconnect the current local branch from its remote tracking branch, which can help avoid accidental pushes or pulls to the wrong remote branch. It operates by removing the association between your local branch and the remote branch it was tracking, so future git pull
or git push
commands will not automatically target the previously linked remote branch.
After running this command, your branch will no longer have an upstream set, and you will need to specify a remote and branch explicitly when pushing or pulling. You can re-establish an upstream branch later using git branch --set-upstream-to=<remote>/<branch>
or git push -u <remote> <branch>
. The shortcut -u
is equivalent to --set-upstream-to
and can be used for convenience.
Related commands include git branch -vv
to view current upstream settings, and git branch --set-upstream-to=<remote>/<branch>
to change or set a new upstream branch. To see all branches and their upstreams, use git branch -vv
. To remove the upstream from a different branch, use git branch --unset-upstream <branch-name>
.