How do you stop tracking a remote branch in Git?

How do you stop tracking a remote branch in Git?

I am asking to stop tracking because in my concrete case, I want to delete the local branch, but not the remote one. Deleting the local one and pushing the deletion to remote will delete the remote branch as well:

  • How do I delete a Git branch both locally and in GitHub?
  • Can I just do git branch -d the_branch , and it won't get propagated when I later git push ?

    Will it only propagate if I were to run git push origin :the_branch later on?


    As mentioned in Yoshua Wuyts' answer, using git branch :

    git branch --unset-upstream
    

    Other options:

    You don't have to delete your local branch.

    Simply delete your remote tracking branch:

    git branch -d -r origin/<remote branch name>
    

    (This will not delete the branch on the remote repo!)

    See "Having a hard time understanding git-fetch"

    there's no such concept of local tracking branches, only remote tracking branches.
    So origin/master is a remote tracking branch for master in the origin repo

    As mentioned in Dobes Vandermeer's answer, you also need to reset the configuration associated to the local branch:

    git config --unset branch.<branch>.remote
    git config --unset branch.<branch>.merge
    

    Remove the upstream information for <branchname> .
    If no branch is specified it defaults to the current branch.

    (git 1.8+, Oct. 2012, commit b84869e by Carlos Martín Nieto ( carlosmn ))

    That will make any push/pull completely unaware of origin/<remote branch name> .


    To remove the upstream for the current branch do:

    $ git branch --unset-upstream
    

    This is available for Git v.1.8.0 or newer. (Sources: 1.7.9 ref, 1.8.0 ref)

    source


    To remove the association between the local and remote branch run:

    git config --unset branch.<local-branch-name>.remote
    git config --unset branch.<local-branch-name>.merge
    

    Optionally delete the local branch afterwards if you don't need it:

    git branch -d <branch>
    

    This won't delete the remote branch.

    链接地址: http://www.djcxy.com/p/670.html

    上一篇: Git获取远程分支

    下一篇: 你如何停止在Git中跟踪远程分支?