Programming

Why call git branch --unset-upstream to fixup

19 September 2026 · 16 min read

Why call git branch --unset-upstream to fixup

Have you ever found yourself wrestling with Git, trying to clean up a branch that seems to be inexplicably linked to a remote tracking branch, even when it shouldn’t be? Perhaps you’ve renamed a local branch, or the remote branch it was tracking no longer exists. This is where the command git branch --unset-upstream becomes a lifesaver. Understanding why to call git branch –unset-upstream when performing branch fixups is crucial for maintaining a clean and manageable Git repository. It’s not just about removing a link; it’s about preventing unexpected behavior and ensuring your local branches operate as intended, free from the constraints of outdated remote tracking information. This article will delve into the nuances of this command, exploring its purpose, usage, and the scenarios where it proves invaluable.

Understanding Git Upstream Tracking

Before diving into the specifics of git branch –unset-upstream, it’s essential to grasp the concept of “upstream tracking” in Git. Upstream tracking establishes a connection between a local branch and a remote branch. This connection allows Git to provide helpful information, such as whether your local branch is ahead or behind the remote branch, and simplifies operations like pulling and pushing changes. When you clone a repository or create a branch that tracks a remote branch, Git automatically sets up this upstream tracking. However, this connection can become problematic if the remote branch is deleted, renamed, or if you intend to repurpose the local branch for a different feature or task. The upstream branch is configured by the branch..remote and branch..merge settings in your .git/config file. These settings dictate which remote repository and which branch are considered the “upstream” for your local branch.

Upstream tracking simplifies development workflows. For example, when you run git pull without specifying a branch, Git knows which remote branch to fetch and merge based on the upstream tracking configuration. Similarly, git push without specifying a remote and branch will push to the configured upstream. However, if the upstream tracking is incorrect or no longer valid, these commands can lead to unexpected results or errors. It’s similar to having outdated contact information for someone; you might try to reach them at an old number or address, leading to frustration and miscommunication. In the context of Git, incorrect upstream tracking can lead to pushing changes to the wrong remote branch, or failing to fetch updates from the correct source. This is why understanding how to manage and, when necessary, remove upstream tracking is crucial for effective Git usage.

To view the current upstream branch that your local branch is tracking, you can use the command git branch -vv. This command displays a list of your local branches, along with information about their upstream branches and their status (e.g., “ahead”, “behind”). If a branch is not tracking any remote, it will simply show the name of the local branch without any upstream information. This command is a valuable tool for diagnosing potential issues with upstream tracking and determining whether it’s necessary to use git branch –unset-upstream. According to Atlassian, a leading provider of developer tools, “Understanding how Git tracks branches is key to collaborating effectively on projects” Atlassian Git Tutorials. This command empowers developers to ensure their local branches are correctly configured and aligned with their intended remote counterparts.

Why Unset Upstream? Scenarios and Use Cases

There are several scenarios where calling git branch –unset-upstream becomes necessary for effective branch management and “fixups”. One common situation arises when a remote branch has been deleted. If your local branch is still tracking this deleted remote branch, Git will throw errors when you try to pull or push changes. Unsetting the upstream tracking resolves this issue by removing the invalid link. Another scenario occurs when you rename a local branch. After renaming, the branch might still be tracking the old upstream, which is no longer relevant. In such cases, unsetting the upstream and potentially setting a new one is the correct approach. Think of it like moving to a new house; you need to update your mailing address to ensure your mail gets delivered to the right place.

Furthermore, if you’re repurposing a local branch for a completely different feature or task, unsetting the upstream is crucial. Continuing to track the old upstream could lead to accidental merges or pushes to the wrong remote branch, potentially introducing bugs or breaking changes. In this situation, you’re essentially starting a new project on the same land, and you need to clear the existing structures before building something new. Consider a scenario where you’ve been working on a feature branch called feature/old-feature, and the feature has been merged into the main branch. Now, you want to use the same branch name feature/old-feature for a completely unrelated new feature. Before starting work on the new feature, you should unset the upstream to avoid any conflicts or confusion with the old feature’s tracking information. This ensures that your new work is isolated and doesn’t inadvertently affect the old feature.

Here’s a featured snippet-optimized paragraph: To unset the upstream branch in Git, use the command git branch –unset-upstream. This command removes the tracking information for the specified local branch, disconnecting it from its remote counterpart. This is particularly useful when the remote branch no longer exists, or when you want to repurpose the local branch for a different feature. Unsetting the upstream prevents errors and ensures that git pull and git push commands behave as expected. Remember to specify the branch name if you’re not currently on the branch you wish to modify, for example, git branch –unset-upstream my-branch.

How to Use git branch –unset-upstream

Using git branch –unset-upstream is straightforward. The basic syntax is: git branch –unset-upstream [<branch_name>]. If you are currently on the branch you want to modify, you can simply run git branch –unset-upstream. Git will automatically unset the upstream for the current branch. If you want to unset the upstream for a different branch, you need to specify the branch name as an argument. For example, to unset the upstream for a branch named my-feature-branch, you would run git branch –unset-upstream my-feature-branch. It’s good practice to double-check the branch name to avoid accidentally unsetting the upstream for the wrong branch.</branch_name>

After running the command, you can verify that the upstream has been successfully unset by using the git branch -vv command again. This command will show that the specified branch no longer has any upstream tracking information. It’s also important to note that git branch –unset-upstream only modifies the local Git configuration. It does not affect the remote repository in any way. This means that unsetting the upstream on your local machine will not delete or modify any remote branches. It simply removes the connection between your local branch and the remote branch.

Here are the steps to unset the upstream branch:

  1. Open your terminal or Git Bash.
  2. Navigate to your Git repository using the cd command.
  3. Checkout the branch you wish to modify using git checkout <branch_name>, or skip this step if you’re already on the desired branch.</branch_name>
  4. Run the command git branch –unset-upstream.
  5. Verify the change by running git branch -vv.

Best Practices and Troubleshooting

While git branch –unset-upstream is a relatively simple command, there are some best practices to keep in mind to avoid potential issues. First, always double-check the branch name before running the command, especially when specifying a branch name as an argument. Accidentally unsetting the upstream for the wrong branch can lead to confusion and potentially disrupt your workflow. Second, if you’re unsure whether to unset the upstream, take a moment to assess the situation. Ask yourself: Is the remote branch still relevant? Am I repurposing the local branch for a different task? If the answer to either of these questions is yes, then unsetting the upstream is likely the right course of action.

Another best practice is to communicate with your team members when making changes to branch tracking configurations. If you’re working on a shared repository, it’s important to ensure that everyone is aware of any changes that might affect their workflow. This can help prevent misunderstandings and ensure that everyone is on the same page. If you encounter errors after unsetting the upstream, such as problems with pulling or pushing changes, the first step is to verify that you have correctly configured your remote repositories. Use the command git remote -v to list your remote repositories and ensure that they are pointing to the correct URLs. If the remote repositories are configured correctly, you may need to set a new upstream using the git branch –set-upstream-to command. This command allows you to establish a new connection between your local branch and a remote branch.

Here are some key takeaways regarding git branch –unset-upstream:

  • Use it when a remote branch is deleted or no longer relevant.
  • Verify the branch name before running the command.
  • Communicate changes to your team.

And here are some common problems and solutions:

  • Problem: Accidentally unset upstream for the wrong branch. Solution: Immediately set the upstream again using git branch –set-upstream-to.
  • Problem: Errors when pulling or pushing after unsetting upstream. Solution: Verify remote repository configurations using git remote -v.
Infographic here
FAQ ---
What happens if I don't unset the upstream when it's no longer valid?
If you don't unset the upstream, you might encounter errors when trying to pull or push changes. Git will attempt to interact with a remote branch that no longer exists, leading to failed operations.
Is git branch --unset-upstream reversible?
Yes, it is reversible. You can set a new upstream using the git branch --set-upstream-to command.
Does git branch --unset-upstream affect the remote repository?
No, it only affects your local Git configuration. It does not modify the remote repository in any way.
When should I use git branch --unset-upstream vs. git remote prune?
git branch --unset-upstream unsets the upstream tracking for a local branch, while git remote prune removes stale remote-tracking branches from your local repository. They serve different purposes but can be used together to maintain a clean repository. According to GitHub documentation, keeping your repository clean is crucial for efficient collaboration [GitHub Docs](https://docs.github.com/).
Understanding **why to call git branch --unset-upstream** is a fundamental skill for any Git user. It allows you to maintain a clean and manageable repository, prevent errors, and ensure that your local branches operate as intended. By following the best practices outlined in this article, you can confidently use this command to fixup your branches and streamline your Git workflow. Don't let outdated upstream tracking hold you back; take control of your Git repository and ensure a smooth and efficient development experience.

Now that you understand the importance of unsetting upstream tracking, take a moment to review your current Git branches. Are there any branches that are tracking outdated or irrelevant remote branches? If so, use git branch –unset-upstream to clean them up and prevent potential issues down the line. For more advanced Git tips and tricks, consider exploring topics like Git rebase, interactive staging, or custom Git aliases. Ensuring your Git skills are always sharp contributes to a more productive workflow, allowing you to focus on building great things. Also, consider looking into Git merge conflicts.

For a deeper dive, explore resources like the official Git documentation Git Documentation and Pro Git book Pro Git Book. These resources offer comprehensive information and advanced techniques for mastering Git.

Question & Answer :
I’m more of a novice when it comes to advanced operations in git. I maintain my blog using the blogging framework Octopress. Though Octopress is not under any development since 2011, it serves my purpose well and so I haven’t thought of changing anything so far.

FYI, my blog is hosted on Github Pages.

Today, while working on a new post, git status showed the following message:

On branch source Your branch is based on 'origin/master', but the upstream is gone. (use "git branch --unset-upstream" to fixup) 

The same message repeated for all the subsequent commands such as git add ., git commit -m 'message' and git push origin source.

  • What does the message mean?
  • Is something broken?
  • If yes, what?
  • Do I need to fix it?

If possible, please point me to a pdf/web article where I can read up on this and understand it for future.

More details:

bash-3.2$ git branch -a * source remotes/octopress/2.1 remotes/octopress/HEAD -> octopress/master remotes/octopress/gh-pages remotes/octopress/linklog remotes/octopress/master remotes/octopress/refactor_with_tests remotes/octopress/rubygemcli remotes/octopress/site remotes/origin/source 

Please let me know if more information is needed. Thanks.

TL;DR version: remote-tracking branch origin/master used to exist, but does not now, so local branch source is tracking something that does not exist, which is suspicious at best—it means a different Git feature is unable to do anything for you—and Git is warning you about it. You have been getting along just fine without having the “upstream tracking” feature work as intended, so it’s up to you whether to change anything.

For another take on upstream settings, see Why do I have to “git push –set-upstream origin <branch>”?


This warning is a new thing in Git, appearing first in Git 1.8.5. The release notes contain just one short bullet-item about it:

  • “git branch -v -v” (and “git status”) did not distinguish among a branch that is not based on any other branch, a branch that is in sync with its upstream branch, and a branch that is configured with an upstream branch that no longer exists.

To describe what it means, you first need to know about “remotes”, “remote-tracking branches”, and how Git handles “tracking an upstream”. (Remote-tracking branches is a terribly flawed term—I’ve started using remote-tracking names instead, which I think is a slight improvement. Below, though, I’ll use “remote-tracking branch” for consistency with Git documentation.)

Each “remote” is simply a name, like origin or octopress in this case. Their purpose is to record things like the full URL of the places from which you git fetch or git pull updates. When you use git fetch <em>remote</em>,1 Git goes to that remote (using the saved URL) and brings over the appropriate set of updates. It also records the updates, using “remote-tracking branches”.

A “remote-tracking branch” (or remote-tracking name) is simply a recording of a branch name as-last-seen on some “remote”. Each remote is itself a Git repository, so it has branches. The branches on remote “origin” are recorded in your local repository under remotes/origin/. The text you showed says that there’s a branch named source on origin, and branches named 2.1, linklog, and so on on octopress.

(A “normal” or “local” branch, of course, is just a branch-name that you have created in your own repository.)

Last, you can set up a (local) branch to “track” a “remote-tracking branch”. Once local branch L is set to track remote-tracking branch R, Git will call R its “upstream” and tell you whether you’re “ahead” and/or “behind” the upstream (in terms of commits). It’s normal (even recommend-able) for the local branch and remote-tracking branches to use the same name (except for the remote prefix part), like source and origin/source, but that’s not actually necessary.

And in this case, that’s not happening. You have a local branch source tracking a remote-tracking branch origin/master.

You’re not supposed to need to know the exact mechanics of how Git sets up a local branch to track a remote one, but they are relevant below, so I’ll show how this works. We start with your local branch name, source. There are two configuration entries using this name, spelled branch.source.remote and branch.source.merge. From the output you showed, it’s clear that these are both set, so that you’d see the following if you ran the given commands:

$ git config --get branch.source.remote origin $ git config --get branch.source.merge refs/heads/master 

Putting these together,2 this tells Git that your branch source tracks your “remote-tracking branch”, origin/master.

But now look at the output of git branch -a, which shows all the local and remote-tracking branch names in your repository. The remote-tracking names are listed under remotes/ … and there is no remotes/origin/master. Presumably there was, at one time, but it’s gone now.

Git is telling you that you can remove the tracking information with --unset-upstream. This will clear out both branch.source.origin and branch.source.merge, and stop the warning.

It seems fairly likely that what you want, though, is to switch from tracking origin/master, to tracking something else: probably origin/source, but maybe one of the octopress/ names.

You can do this with git branch --set-upstream-to,3 e.g.:

$ git branch --set-upstream-to=origin/source 

(assuming you’re still on branch “source”, and that origin/source is the upstream you want—there is no way for me to tell which one, if any, you actually want, though).

(See also How do you make an existing Git branch track a remote branch?)

I think the way you got here is that when you first did a git clone, the thing you cloned-from had a branch master. You also had a branch master, which was set to track origin/master (this is a normal, standard setup for git). This meant you had branch.master.remote and branch.master.merge set, to origin and refs/heads/master. But then your origin remote changed its name from master to source. To match, I believe you also changed your local name from master to source. This changed the names of your settings, from branch.master.remote to branch.source.remote and from branch.master.merge to branch.source.merge … but it left the old values, so branch.source.merge was now wrong.

It was at this point that the “upstream” linkage broke, but in Git versions older than 1.8.5, Git never noticed the broken setting. Now that you have 1.8.5, it’s pointing this out.


That covers most of the questions, but not the “do I need to fix it” one. It’s likely that you have been working around the broken-ness for years now, by doing git pull <em>remote branch</em> (e.g., git pull origin source). If you keep doing that, it will keep working around the problem—so, no, you don’t need to fix it. If you like, you can use --unset-upstream to remove the upstream and stop the complaints, and not have local branch source marked as having any upstream at all.

The point of having an upstream is to make various operations more convenient. For instance, git fetch followed by git merge will generally “do the right thing” if the upstream is set correctly, and git status after git fetch will tell you whether your repo matches the upstream one, for that branch.

If you want the convenience, re-set the upstream.


1git pull uses git fetch, and as of Git 1.8.4, this (finally!) also updates the “remote-tracking branch” information. In older versions of Git, the updates did not get recorded in remote-tracking branches with git pull, only with git fetch. Since your Git must be at least version 1.8.5 this is not an issue for you.

2Well, this plus a configuration line I’m deliberately ignoring that is found under remote.origin.fetch. Git has to map the “merge” name to figure out that the full local name for the remote-branch is refs/remotes/origin/master. The mapping almost always works just like this, though, so it’s predictable that master goes to origin/master.

3Or, with git config. If you just want to set the upstream to origin/source the only part that has to change is branch.source.merge, and git config branch.source.merge refs/heads/source would do it. But --set-upstream-to says what you want done, rather than making you go do it yourself manually, so that’s a “better way”.