Home > Net >  I have two branches in my git. The one is in green (master) other (personal-website/master) is in re
I have two branches in my git. The one is in green (master) other (personal-website/master) is in re

Time:05-19

why the second branch is showing in red color. And also when I entered git branch there is only one branch: master. When I tried to delete second branch (personal-website/master), it showing error (branch 'personal-website/master' not found). What could be the issue. How to remove it? [image attached below]

git terminal

CodePudding user response:

The personal-website/master is a remote branch that presents an upstream to your local branch master. In order to remove your remote branch, you need to perform a delete push as illustrated below:

git push personal-website master --delete

CodePudding user response:

The red color here does not indicate any kind of error. Instead, it distinguishes a remote-tracking name from a branch name. By default, when Git applies color to branch names, it puts local branch names in green and remote-tracking names in red.

A remote-tracking name is a name that your Git software maintains in your Git repository based on a branch name that your Git software observed in some other Git repository. Git is a distributed version control system—a "DVCS", with the D standing for distributed—which in this case means that repositories get replicated. The replicas can be exact duplicates, or approximate duplicates. As you add new commits to your repository, your duplicate of their repository becomes less-exact, because the new commits you have added to your repository are, at this point, only in your repository.

Your branch names, in your repository, exist to help you keep track of your commits. Git itself doesn't actually need any branch names: Git finds commits by their hash IDs, which are very large numbers, expressed in hexadecimal.

Every commit gets a unique hash ID, and two separate repositories have the same commit if and only if they have a commit that has the same hash ID. So two repositories, meeting up with git push or git fetch, can tell which commits they both share, and which commits one repository has that the other repository lacks, just by comparing hash IDs.1 It's the commits, and their numbers, that actually matter to Git. But the numbers look random and are not usable by mere humans, so we use names: branch names in particular.

But your branch names, in your repository, are your names. You get to do whatever you want with them. They're not anyone else's branch names. Those other repositories you have your repository call up, and give commits to or get commits from or both, have their own branch names that remember commit hash IDs for them.

When your Git software calls up their Git software, your Git code gets to see what their names are and what hash IDs are stored in them. Your Git will take those names and change them into remote-tracking names, and stuff those remote-tracking names into your repository. By changing the names, your Git ensures that their branch names don't collide with yours. But now it may be important to you to be able to see, at a glance, which names are whose. The color distinction is there to help out with that.

As long as you ever intend to connect to their repository again, you should not worry about your own Git carrying around their branch names (translated into your remote-tracking names). If the red color bothers you, you can instruct your Git software to use some other color, you can configure some settings:

  • color.branch.remote controls the remote-tracking-name color from git branch -r or git branch -a.
  • color.decorate.remoteBranch controls the remote-tracking-name color from git log.

(Why one is remote and one is remoteBranch is a mystery and a historical oddity. However, Git documentation often uses the phrase remote-tracking branch name instead of the simpler remote-tracking name.)

Removing the remote entirely, as in William Pursell's comment, will remove the remote-tracking name as well. However, this means you can no longer run git fetch personal-website or git push personal-website to conveniently obtain new commits from the other Git repository, or send your commits to the remote repository. (You can still get and send commits, you just cannot do it conveniently by using the short word personal-website. That short word personal-website is what Git calls a remote.)


1This unique hash ID trick is the real magic of Git: how it manages to make sure that no two repositories ever accidentally use the same number for a different commit, and yet always use the same number for the same commit, is a mathematical marvel. It's also fundamentally flawed: someday, Git will fail. The sheer size of the number space puts that day off for a long time: billions or trillions of years, we hope, so that we'll all be long dead and won't care.

  • Related