Stop tracking a remote branch in Git
This article explains how we can stop tracking a remote branch in Git. By now, you must be very familiar with the concept of tracking remote branches.
This session will cover the various methods you can use to stop tracking a remote branch. Let's jump right in.
Stop tracking a remote branch in Git
This is a list of all the remote-tracking branches in our repository.
If you recall, newer versions of Git will show remote tracking branches in blue. So we can see that Dev2.1 in our local repository is tracking Dev2.1 in our remote origin.
We can stop tracking a remote branch using the following steps.
First, we will checkout the Dev2.1 branch as shown below.
$ git checkout Dev2.1
We can now run the following command to stop tracking the remote branch.
$ git branch --unset-upstream
As soon as we execute the command, our Dev2.1 will stop tracking the remote branch. Let's check if this is the case.
We can see that our Dev2.1 branch has no remote-tracking branch.
请注意
, when you stop tracking a remote branch, you will no longer be able to push changes made in your local repository to the remote branch.
Other options
Alternatively, you can delete the remote-tracking branches in your local repository. This doesn't work for everyone.
This is a quick solution for those who no longer need branches.
$ git branch -d -r origin/<remote branch name>
Replace the remote branch name with the name of the tracking branch. This command does not delete the branch in the remote repository.
It only unsets the branch used to track the remote.
Another way to handle this is to edit the configuration file to remove the link between the local and remote branches.
Run the command below.
$ git config --unset branch.<local-branch-name>.remote
$ git config --unset branch.<local-branch-name>.merge
This will edit the configuration to remove the association between the remote and local branches.
In short, we have covered three methods that can be used to stop tracking a remote branch. git branch --unset-upstream
The command is the cleanest and simplest.
You can also remove the link between two branches by editing the Git configuration file.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Switch remote Git branch
Publish Date:2025/04/04 Views:182 Category:Git
-
This article will show you how to switch remote Git branches using checkout the command. The version control tool that allows you to support and manage variable versions of your application in a team of members is the Git version control to
Creating a branch from a tag in Git
Publish Date:2025/04/04 Views:93 Category:Git
-
This article introduces how we can create a new branch based on a tag in Git. If you are a regular Git user, you must know the purpose of Git tags. These tags are just pointers to meaningful Git commits. The question is: how do you create a
Git shows remote tracking branches
Publish Date:2025/04/03 Views:126 Category:Git
-
Branches on remote Git repositories are called remote branches. These are pointers to our remote repositories, including branches, tags, etc. Local branches only exist on each developer's local personal computer, but there is only one remot
View merged and unmerged branches in Git
Publish Date:2025/04/03 Views:97 Category:Git
-
This article discusses how to list merged and unmerged branches in Git. Git branches encourage convergent evolution of code. This is where we create a branch as a temporary space to work on a feature, and then merge the branch with its orig
The difference between Fork and Branch on GitHub
Publish Date:2025/04/03 Views:157 Category:Git
-
This article discusses the difference between Form and Branch on GitHub. In the context of coding, the current era relies more on collaboration. GitHub is one of the most commonly used collaboration tools. Forking and branching on GitHub ar
How to determine the current branch in Git
Publish Date:2025/04/03 Views:165 Category:Git
-
Git is a unique and popular version control system that is used by most of the software developers to keep an eye on the changes made in various applications and stay connected with other teams on the running projects. It helps large teams
Difference between Git Merge Origin/Master and Git Pull
Publish Date:2025/04/03 Views:196 Category:Git
-
This article outlines the differences between the git merge origin/master and git pull commands. These two commands integrate changes from a remote repository into the current local branch. However, each command's operation is unique and ha
Git Pull Origin branch overwrites Master branch
Publish Date:2025/04/03 Views:144 Category:Git
-
This article explains how we can revert the changes made to the master git pull origin branch branch after running the command . Assume that you have a master branch and a feature branch in your local and remote repositories . You pull chan
Git Pull and Merge Commands
Publish Date:2025/04/03 Views:56 Category:Git
-
In the vast world of version control systems, Git is the only fast, well-organized, in-demand, and easily accessible version control system that enables users to work on various projects simultaneously in an efficient manner without any col