Why does “git status” show I'm on the master branch and “git branch” does not in a newly created repository?How to programmatically determine the current checked out Git branchGit workflow and rebase vs merge questionsHow to fully delete a git repository created with init?How do you create a remote Git branch?Make the current Git branch a master branchHow do I push a new local branch to a remote Git repository and track it too?How to replace master branch in Git, entirely, from another branch?Message 'src refspec master does not match any' when pushing commits in GitIs it possible to cherry-pick a commit from another git repository?What is the best (and safest) way to merge a Git branch into master?How can I reconcile detached HEAD with master/origin?
How could an animal "smell" carbon monoxide?
Is there an English equivalent for "Les carottes sont cuites", while keeping the vegetable reference?
Coverting list of string into integers and reshaping the original list
Cover a cube with four-legged walky-squares!
Pi 3 B+ no audio device found
Is it ethical for a company to ask its employees to move furniture on a weekend?
Improve quality of image bars
A verb to describe specific positioning of three layers
How many bits in the resultant hash will change, if the x bits are changed in its the original input?
Generating a PIN from cryptographic bytes
Vienna To Graz By Rail
Is straight-up writing someone's opinions telling?
Is passive Investigation essentially truesight against illusions?
At which point can a system be compromised when downloading archived data from an untrusted source?
Is this artwork (used in a video game) real?
Will this tire fail its MOT?
Alphanumeric Line and Curve Counting
How to honestly answer questions from a girlfriend like "How did you find this place" without giving the impression I'm always talking about my exes?
Why does FFmpeg choose 10+20+20 ms instead of an even 16 ms for 60 fps GIF images?
Which GPUs to get for Mathematical Optimization (if any...)?
What are the first usages of "thong" as a wearable item of clothing, both on the feet and on the waist?
Can you perfectly wrap a cube with this blocky shape?
Does inertia keep a rotating object rotating forever, or something else?
How to remove the first colon ':' from a timestamp?
Why does “git status” show I'm on the master branch and “git branch” does not in a newly created repository?
How to programmatically determine the current checked out Git branchGit workflow and rebase vs merge questionsHow to fully delete a git repository created with init?How do you create a remote Git branch?Make the current Git branch a master branchHow do I push a new local branch to a remote Git repository and track it too?How to replace master branch in Git, entirely, from another branch?Message 'src refspec master does not match any' when pushing commits in GitIs it possible to cherry-pick a commit from another git repository?What is the best (and safest) way to merge a Git branch into master?How can I reconcile detached HEAD with master/origin?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to automate a process and issue the git branch
command to find out what branch I am on. Everything is working fine except for a newly initialized repo where git branch
returns nothing. Given I've done nothing with the repo, not even the initial commit, I can accept the answer. However, if I run a git status
it tells be I'm on the master
branch, as seen here:
$ mkdir todelete
$ cd todelete
$ git init
Initialized empty Git repository in /u/u70021a/todelete/.git
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
$ git branch
$
Am I doing something wrong? Is there some setting I haven't set properly?
I also have a number of new people to Git and I can't explain to them why the command to show you which branch they are on shows nothing, yet the status command does.
git
add a comment |
I'm trying to automate a process and issue the git branch
command to find out what branch I am on. Everything is working fine except for a newly initialized repo where git branch
returns nothing. Given I've done nothing with the repo, not even the initial commit, I can accept the answer. However, if I run a git status
it tells be I'm on the master
branch, as seen here:
$ mkdir todelete
$ cd todelete
$ git init
Initialized empty Git repository in /u/u70021a/todelete/.git
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
$ git branch
$
Am I doing something wrong? Is there some setting I haven't set properly?
I also have a number of new people to Git and I can't explain to them why the command to show you which branch they are on shows nothing, yet the status command does.
git
add a comment |
I'm trying to automate a process and issue the git branch
command to find out what branch I am on. Everything is working fine except for a newly initialized repo where git branch
returns nothing. Given I've done nothing with the repo, not even the initial commit, I can accept the answer. However, if I run a git status
it tells be I'm on the master
branch, as seen here:
$ mkdir todelete
$ cd todelete
$ git init
Initialized empty Git repository in /u/u70021a/todelete/.git
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
$ git branch
$
Am I doing something wrong? Is there some setting I haven't set properly?
I also have a number of new people to Git and I can't explain to them why the command to show you which branch they are on shows nothing, yet the status command does.
git
I'm trying to automate a process and issue the git branch
command to find out what branch I am on. Everything is working fine except for a newly initialized repo where git branch
returns nothing. Given I've done nothing with the repo, not even the initial commit, I can accept the answer. However, if I run a git status
it tells be I'm on the master
branch, as seen here:
$ mkdir todelete
$ cd todelete
$ git init
Initialized empty Git repository in /u/u70021a/todelete/.git
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
$ git branch
$
Am I doing something wrong? Is there some setting I haven't set properly?
I also have a number of new people to Git and I can't explain to them why the command to show you which branch they are on shows nothing, yet the status command does.
git
git
edited 1 hour ago
blahdiblah
25.6k17 gold badges84 silver badges142 bronze badges
25.6k17 gold badges84 silver badges142 bronze badges
asked yesterday
GOVarneyGOVarney
3183 silver badges5 bronze badges
3183 silver badges5 bronze badges
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
I upvoted two other answers, but I think the way to think of this is simple: You can be on a branch that doesn't exist. That's normal in a new empty repository, too, because for a branch name to exist, that branch name must identify the hash ID of an existing, valid commit. A new empty repository has no commits, so no branch names are allowed to exist yet.
Nonetheless, you are, initially, on some branch. The branch you are on is the one whose name is stored in the special name HEAD
. In a new, empty repository, Git stores the name master
(more precisely, refs/heads/master
—the full name of the branch) in HEAD
, so you are on master
, while master
does not exist.
You can change which non-existent branch you are on using git checkout -b
:
$ git init
Initialized empty Git repository in [path]
$ git checkout -b asdf
Switched to a new branch 'asdf'
$ git checkout -b hello
Switched to a new branch 'hello'
Whenever you are on a branch that does not exist, the next commit you make creates the branch. This is also how git checkout --orphan
works.
3
Thanks. While I don't agree with what git is displaying. At least I understand why. Your checkout example is interesting. According to the documentation for "git checkout" the -b means: Create a new branch named <new_branch> which isn't strictly true. In your example, neither branch asdf or hello are actually created. But they will be if a commit is performed. My personal opinion is the "On branch master" message should be changed to "Next Commit to branch master" because until a commit is performed the master branch doesn't exist.
– GOVarney
yesterday
1
I'm not sure if this is relevant to your case or not, but I want to point that for Git it is possible to not be on any branch at all.
– sklott
17 hours ago
"While I don't agree with what git is displaying." - it may be worth reporting it is a bug, if someone feels irritated enough :)
– Mateusz Konieczny
16 hours ago
Git internally usescat .git/HEAD
to see what branch it is on, figuring out of the branch exists would consume more CPU and disk time, so that's probably why they didn't do it
– Ferrybig
14 hours ago
What should imo be mentioned is that you should not usegit branch
in an automated process at all because it's not designed for that use case. It would be interesting to see what the non-porcelain commands show here, doesgit symbolic-ref --short HEAD
have the same behavior?
– Voo
6 hours ago
|
show 1 more comment
git branch
shows nothing because there is no branch. But, as you can read in man git init
:
This command creates an empty Git repository - basically a .git directory with subdirectories for objects,
refs/heads, refs/tags, and template files. An initial HEAD file that references the HEAD of the master
branch is also created.
I bolded the part I think is relevant - it looks like although there is no master branch yet, a reference to it already exists and that is why it is shown in git status
. A proper branch will be created upon committing.
1
So it looks like "git status" is just displaying the "branch name" as seen in .git/HEAD (ref: refs/heads/master) but does no consistency check by looking in .git/refs/heads to see if it actually exists.
– GOVarney
yesterday
I cannot tell for sure, as I didn't inspect git's code, but what you wrote makes sense to me. But still I prefer torek's answer over mine :) .
– Stanowczo
yesterday
add a comment |
The branch is unborn, yet. Therefore git branch
doesn’t show it (git symbolic-ref HEAD
indicates that your HEAD is pointing to the default branch master and that it is unborn as git branch
doesn't show it, i.e., you can be on a branch that does not exist yet). However, committing something will create the branch.
This is also the case if you checkout an orphan
branch.
I suppose git status
shows the branch name as this is the branch which will be created.
add a comment |
Existing answers address the literal question of why the output is what it is, but I think they've kind of glossed over the real issue...
You said you're automating something, so I would suggest that neither git status
nor git branch
is the best tool in a scripting context.
Some alternatives can be found in this discussion: How to programmatically determine the current checked out Git branch
Without knowing your needs (or how you would want an unborn branch to behave) I can't necessarily make a recommendation, but the point I'm getting at is, some commands are for human interaction (porcelain) and others are for scripts (plumbing)
add a comment |
In git the default branch is master
.
When you commit git will "use" the current branch which you on right now.
Since you have initialized a new repository you are on the "default" branch and this is why you don't see it in your branches list, it will show up once you commit your changes.
I understand branching, I don't understand why "git status" says I'm on a branch that doesn't exist.
– GOVarney
yesterday
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f57051056%2fwhy-does-git-status-show-im-on-the-master-branch-and-git-branch-does-not-in%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
I upvoted two other answers, but I think the way to think of this is simple: You can be on a branch that doesn't exist. That's normal in a new empty repository, too, because for a branch name to exist, that branch name must identify the hash ID of an existing, valid commit. A new empty repository has no commits, so no branch names are allowed to exist yet.
Nonetheless, you are, initially, on some branch. The branch you are on is the one whose name is stored in the special name HEAD
. In a new, empty repository, Git stores the name master
(more precisely, refs/heads/master
—the full name of the branch) in HEAD
, so you are on master
, while master
does not exist.
You can change which non-existent branch you are on using git checkout -b
:
$ git init
Initialized empty Git repository in [path]
$ git checkout -b asdf
Switched to a new branch 'asdf'
$ git checkout -b hello
Switched to a new branch 'hello'
Whenever you are on a branch that does not exist, the next commit you make creates the branch. This is also how git checkout --orphan
works.
3
Thanks. While I don't agree with what git is displaying. At least I understand why. Your checkout example is interesting. According to the documentation for "git checkout" the -b means: Create a new branch named <new_branch> which isn't strictly true. In your example, neither branch asdf or hello are actually created. But they will be if a commit is performed. My personal opinion is the "On branch master" message should be changed to "Next Commit to branch master" because until a commit is performed the master branch doesn't exist.
– GOVarney
yesterday
1
I'm not sure if this is relevant to your case or not, but I want to point that for Git it is possible to not be on any branch at all.
– sklott
17 hours ago
"While I don't agree with what git is displaying." - it may be worth reporting it is a bug, if someone feels irritated enough :)
– Mateusz Konieczny
16 hours ago
Git internally usescat .git/HEAD
to see what branch it is on, figuring out of the branch exists would consume more CPU and disk time, so that's probably why they didn't do it
– Ferrybig
14 hours ago
What should imo be mentioned is that you should not usegit branch
in an automated process at all because it's not designed for that use case. It would be interesting to see what the non-porcelain commands show here, doesgit symbolic-ref --short HEAD
have the same behavior?
– Voo
6 hours ago
|
show 1 more comment
I upvoted two other answers, but I think the way to think of this is simple: You can be on a branch that doesn't exist. That's normal in a new empty repository, too, because for a branch name to exist, that branch name must identify the hash ID of an existing, valid commit. A new empty repository has no commits, so no branch names are allowed to exist yet.
Nonetheless, you are, initially, on some branch. The branch you are on is the one whose name is stored in the special name HEAD
. In a new, empty repository, Git stores the name master
(more precisely, refs/heads/master
—the full name of the branch) in HEAD
, so you are on master
, while master
does not exist.
You can change which non-existent branch you are on using git checkout -b
:
$ git init
Initialized empty Git repository in [path]
$ git checkout -b asdf
Switched to a new branch 'asdf'
$ git checkout -b hello
Switched to a new branch 'hello'
Whenever you are on a branch that does not exist, the next commit you make creates the branch. This is also how git checkout --orphan
works.
3
Thanks. While I don't agree with what git is displaying. At least I understand why. Your checkout example is interesting. According to the documentation for "git checkout" the -b means: Create a new branch named <new_branch> which isn't strictly true. In your example, neither branch asdf or hello are actually created. But they will be if a commit is performed. My personal opinion is the "On branch master" message should be changed to "Next Commit to branch master" because until a commit is performed the master branch doesn't exist.
– GOVarney
yesterday
1
I'm not sure if this is relevant to your case or not, but I want to point that for Git it is possible to not be on any branch at all.
– sklott
17 hours ago
"While I don't agree with what git is displaying." - it may be worth reporting it is a bug, if someone feels irritated enough :)
– Mateusz Konieczny
16 hours ago
Git internally usescat .git/HEAD
to see what branch it is on, figuring out of the branch exists would consume more CPU and disk time, so that's probably why they didn't do it
– Ferrybig
14 hours ago
What should imo be mentioned is that you should not usegit branch
in an automated process at all because it's not designed for that use case. It would be interesting to see what the non-porcelain commands show here, doesgit symbolic-ref --short HEAD
have the same behavior?
– Voo
6 hours ago
|
show 1 more comment
I upvoted two other answers, but I think the way to think of this is simple: You can be on a branch that doesn't exist. That's normal in a new empty repository, too, because for a branch name to exist, that branch name must identify the hash ID of an existing, valid commit. A new empty repository has no commits, so no branch names are allowed to exist yet.
Nonetheless, you are, initially, on some branch. The branch you are on is the one whose name is stored in the special name HEAD
. In a new, empty repository, Git stores the name master
(more precisely, refs/heads/master
—the full name of the branch) in HEAD
, so you are on master
, while master
does not exist.
You can change which non-existent branch you are on using git checkout -b
:
$ git init
Initialized empty Git repository in [path]
$ git checkout -b asdf
Switched to a new branch 'asdf'
$ git checkout -b hello
Switched to a new branch 'hello'
Whenever you are on a branch that does not exist, the next commit you make creates the branch. This is also how git checkout --orphan
works.
I upvoted two other answers, but I think the way to think of this is simple: You can be on a branch that doesn't exist. That's normal in a new empty repository, too, because for a branch name to exist, that branch name must identify the hash ID of an existing, valid commit. A new empty repository has no commits, so no branch names are allowed to exist yet.
Nonetheless, you are, initially, on some branch. The branch you are on is the one whose name is stored in the special name HEAD
. In a new, empty repository, Git stores the name master
(more precisely, refs/heads/master
—the full name of the branch) in HEAD
, so you are on master
, while master
does not exist.
You can change which non-existent branch you are on using git checkout -b
:
$ git init
Initialized empty Git repository in [path]
$ git checkout -b asdf
Switched to a new branch 'asdf'
$ git checkout -b hello
Switched to a new branch 'hello'
Whenever you are on a branch that does not exist, the next commit you make creates the branch. This is also how git checkout --orphan
works.
answered yesterday
torektorek
215k21 gold badges280 silver badges366 bronze badges
215k21 gold badges280 silver badges366 bronze badges
3
Thanks. While I don't agree with what git is displaying. At least I understand why. Your checkout example is interesting. According to the documentation for "git checkout" the -b means: Create a new branch named <new_branch> which isn't strictly true. In your example, neither branch asdf or hello are actually created. But they will be if a commit is performed. My personal opinion is the "On branch master" message should be changed to "Next Commit to branch master" because until a commit is performed the master branch doesn't exist.
– GOVarney
yesterday
1
I'm not sure if this is relevant to your case or not, but I want to point that for Git it is possible to not be on any branch at all.
– sklott
17 hours ago
"While I don't agree with what git is displaying." - it may be worth reporting it is a bug, if someone feels irritated enough :)
– Mateusz Konieczny
16 hours ago
Git internally usescat .git/HEAD
to see what branch it is on, figuring out of the branch exists would consume more CPU and disk time, so that's probably why they didn't do it
– Ferrybig
14 hours ago
What should imo be mentioned is that you should not usegit branch
in an automated process at all because it's not designed for that use case. It would be interesting to see what the non-porcelain commands show here, doesgit symbolic-ref --short HEAD
have the same behavior?
– Voo
6 hours ago
|
show 1 more comment
3
Thanks. While I don't agree with what git is displaying. At least I understand why. Your checkout example is interesting. According to the documentation for "git checkout" the -b means: Create a new branch named <new_branch> which isn't strictly true. In your example, neither branch asdf or hello are actually created. But they will be if a commit is performed. My personal opinion is the "On branch master" message should be changed to "Next Commit to branch master" because until a commit is performed the master branch doesn't exist.
– GOVarney
yesterday
1
I'm not sure if this is relevant to your case or not, but I want to point that for Git it is possible to not be on any branch at all.
– sklott
17 hours ago
"While I don't agree with what git is displaying." - it may be worth reporting it is a bug, if someone feels irritated enough :)
– Mateusz Konieczny
16 hours ago
Git internally usescat .git/HEAD
to see what branch it is on, figuring out of the branch exists would consume more CPU and disk time, so that's probably why they didn't do it
– Ferrybig
14 hours ago
What should imo be mentioned is that you should not usegit branch
in an automated process at all because it's not designed for that use case. It would be interesting to see what the non-porcelain commands show here, doesgit symbolic-ref --short HEAD
have the same behavior?
– Voo
6 hours ago
3
3
Thanks. While I don't agree with what git is displaying. At least I understand why. Your checkout example is interesting. According to the documentation for "git checkout" the -b means: Create a new branch named <new_branch> which isn't strictly true. In your example, neither branch asdf or hello are actually created. But they will be if a commit is performed. My personal opinion is the "On branch master" message should be changed to "Next Commit to branch master" because until a commit is performed the master branch doesn't exist.
– GOVarney
yesterday
Thanks. While I don't agree with what git is displaying. At least I understand why. Your checkout example is interesting. According to the documentation for "git checkout" the -b means: Create a new branch named <new_branch> which isn't strictly true. In your example, neither branch asdf or hello are actually created. But they will be if a commit is performed. My personal opinion is the "On branch master" message should be changed to "Next Commit to branch master" because until a commit is performed the master branch doesn't exist.
– GOVarney
yesterday
1
1
I'm not sure if this is relevant to your case or not, but I want to point that for Git it is possible to not be on any branch at all.
– sklott
17 hours ago
I'm not sure if this is relevant to your case or not, but I want to point that for Git it is possible to not be on any branch at all.
– sklott
17 hours ago
"While I don't agree with what git is displaying." - it may be worth reporting it is a bug, if someone feels irritated enough :)
– Mateusz Konieczny
16 hours ago
"While I don't agree with what git is displaying." - it may be worth reporting it is a bug, if someone feels irritated enough :)
– Mateusz Konieczny
16 hours ago
Git internally uses
cat .git/HEAD
to see what branch it is on, figuring out of the branch exists would consume more CPU and disk time, so that's probably why they didn't do it– Ferrybig
14 hours ago
Git internally uses
cat .git/HEAD
to see what branch it is on, figuring out of the branch exists would consume more CPU and disk time, so that's probably why they didn't do it– Ferrybig
14 hours ago
What should imo be mentioned is that you should not use
git branch
in an automated process at all because it's not designed for that use case. It would be interesting to see what the non-porcelain commands show here, does git symbolic-ref --short HEAD
have the same behavior?– Voo
6 hours ago
What should imo be mentioned is that you should not use
git branch
in an automated process at all because it's not designed for that use case. It would be interesting to see what the non-porcelain commands show here, does git symbolic-ref --short HEAD
have the same behavior?– Voo
6 hours ago
|
show 1 more comment
git branch
shows nothing because there is no branch. But, as you can read in man git init
:
This command creates an empty Git repository - basically a .git directory with subdirectories for objects,
refs/heads, refs/tags, and template files. An initial HEAD file that references the HEAD of the master
branch is also created.
I bolded the part I think is relevant - it looks like although there is no master branch yet, a reference to it already exists and that is why it is shown in git status
. A proper branch will be created upon committing.
1
So it looks like "git status" is just displaying the "branch name" as seen in .git/HEAD (ref: refs/heads/master) but does no consistency check by looking in .git/refs/heads to see if it actually exists.
– GOVarney
yesterday
I cannot tell for sure, as I didn't inspect git's code, but what you wrote makes sense to me. But still I prefer torek's answer over mine :) .
– Stanowczo
yesterday
add a comment |
git branch
shows nothing because there is no branch. But, as you can read in man git init
:
This command creates an empty Git repository - basically a .git directory with subdirectories for objects,
refs/heads, refs/tags, and template files. An initial HEAD file that references the HEAD of the master
branch is also created.
I bolded the part I think is relevant - it looks like although there is no master branch yet, a reference to it already exists and that is why it is shown in git status
. A proper branch will be created upon committing.
1
So it looks like "git status" is just displaying the "branch name" as seen in .git/HEAD (ref: refs/heads/master) but does no consistency check by looking in .git/refs/heads to see if it actually exists.
– GOVarney
yesterday
I cannot tell for sure, as I didn't inspect git's code, but what you wrote makes sense to me. But still I prefer torek's answer over mine :) .
– Stanowczo
yesterday
add a comment |
git branch
shows nothing because there is no branch. But, as you can read in man git init
:
This command creates an empty Git repository - basically a .git directory with subdirectories for objects,
refs/heads, refs/tags, and template files. An initial HEAD file that references the HEAD of the master
branch is also created.
I bolded the part I think is relevant - it looks like although there is no master branch yet, a reference to it already exists and that is why it is shown in git status
. A proper branch will be created upon committing.
git branch
shows nothing because there is no branch. But, as you can read in man git init
:
This command creates an empty Git repository - basically a .git directory with subdirectories for objects,
refs/heads, refs/tags, and template files. An initial HEAD file that references the HEAD of the master
branch is also created.
I bolded the part I think is relevant - it looks like although there is no master branch yet, a reference to it already exists and that is why it is shown in git status
. A proper branch will be created upon committing.
answered yesterday
StanowczoStanowczo
3842 silver badges13 bronze badges
3842 silver badges13 bronze badges
1
So it looks like "git status" is just displaying the "branch name" as seen in .git/HEAD (ref: refs/heads/master) but does no consistency check by looking in .git/refs/heads to see if it actually exists.
– GOVarney
yesterday
I cannot tell for sure, as I didn't inspect git's code, but what you wrote makes sense to me. But still I prefer torek's answer over mine :) .
– Stanowczo
yesterday
add a comment |
1
So it looks like "git status" is just displaying the "branch name" as seen in .git/HEAD (ref: refs/heads/master) but does no consistency check by looking in .git/refs/heads to see if it actually exists.
– GOVarney
yesterday
I cannot tell for sure, as I didn't inspect git's code, but what you wrote makes sense to me. But still I prefer torek's answer over mine :) .
– Stanowczo
yesterday
1
1
So it looks like "git status" is just displaying the "branch name" as seen in .git/HEAD (ref: refs/heads/master) but does no consistency check by looking in .git/refs/heads to see if it actually exists.
– GOVarney
yesterday
So it looks like "git status" is just displaying the "branch name" as seen in .git/HEAD (ref: refs/heads/master) but does no consistency check by looking in .git/refs/heads to see if it actually exists.
– GOVarney
yesterday
I cannot tell for sure, as I didn't inspect git's code, but what you wrote makes sense to me. But still I prefer torek's answer over mine :) .
– Stanowczo
yesterday
I cannot tell for sure, as I didn't inspect git's code, but what you wrote makes sense to me. But still I prefer torek's answer over mine :) .
– Stanowczo
yesterday
add a comment |
The branch is unborn, yet. Therefore git branch
doesn’t show it (git symbolic-ref HEAD
indicates that your HEAD is pointing to the default branch master and that it is unborn as git branch
doesn't show it, i.e., you can be on a branch that does not exist yet). However, committing something will create the branch.
This is also the case if you checkout an orphan
branch.
I suppose git status
shows the branch name as this is the branch which will be created.
add a comment |
The branch is unborn, yet. Therefore git branch
doesn’t show it (git symbolic-ref HEAD
indicates that your HEAD is pointing to the default branch master and that it is unborn as git branch
doesn't show it, i.e., you can be on a branch that does not exist yet). However, committing something will create the branch.
This is also the case if you checkout an orphan
branch.
I suppose git status
shows the branch name as this is the branch which will be created.
add a comment |
The branch is unborn, yet. Therefore git branch
doesn’t show it (git symbolic-ref HEAD
indicates that your HEAD is pointing to the default branch master and that it is unborn as git branch
doesn't show it, i.e., you can be on a branch that does not exist yet). However, committing something will create the branch.
This is also the case if you checkout an orphan
branch.
I suppose git status
shows the branch name as this is the branch which will be created.
The branch is unborn, yet. Therefore git branch
doesn’t show it (git symbolic-ref HEAD
indicates that your HEAD is pointing to the default branch master and that it is unborn as git branch
doesn't show it, i.e., you can be on a branch that does not exist yet). However, committing something will create the branch.
This is also the case if you checkout an orphan
branch.
I suppose git status
shows the branch name as this is the branch which will be created.
edited 16 hours ago
answered yesterday
MrTuxMrTux
22.5k15 gold badges63 silver badges100 bronze badges
22.5k15 gold badges63 silver badges100 bronze badges
add a comment |
add a comment |
Existing answers address the literal question of why the output is what it is, but I think they've kind of glossed over the real issue...
You said you're automating something, so I would suggest that neither git status
nor git branch
is the best tool in a scripting context.
Some alternatives can be found in this discussion: How to programmatically determine the current checked out Git branch
Without knowing your needs (or how you would want an unborn branch to behave) I can't necessarily make a recommendation, but the point I'm getting at is, some commands are for human interaction (porcelain) and others are for scripts (plumbing)
add a comment |
Existing answers address the literal question of why the output is what it is, but I think they've kind of glossed over the real issue...
You said you're automating something, so I would suggest that neither git status
nor git branch
is the best tool in a scripting context.
Some alternatives can be found in this discussion: How to programmatically determine the current checked out Git branch
Without knowing your needs (or how you would want an unborn branch to behave) I can't necessarily make a recommendation, but the point I'm getting at is, some commands are for human interaction (porcelain) and others are for scripts (plumbing)
add a comment |
Existing answers address the literal question of why the output is what it is, but I think they've kind of glossed over the real issue...
You said you're automating something, so I would suggest that neither git status
nor git branch
is the best tool in a scripting context.
Some alternatives can be found in this discussion: How to programmatically determine the current checked out Git branch
Without knowing your needs (or how you would want an unborn branch to behave) I can't necessarily make a recommendation, but the point I'm getting at is, some commands are for human interaction (porcelain) and others are for scripts (plumbing)
Existing answers address the literal question of why the output is what it is, but I think they've kind of glossed over the real issue...
You said you're automating something, so I would suggest that neither git status
nor git branch
is the best tool in a scripting context.
Some alternatives can be found in this discussion: How to programmatically determine the current checked out Git branch
Without knowing your needs (or how you would want an unborn branch to behave) I can't necessarily make a recommendation, but the point I'm getting at is, some commands are for human interaction (porcelain) and others are for scripts (plumbing)
answered yesterday
Mark AdelsbergerMark Adelsberger
23.1k1 gold badge14 silver badges22 bronze badges
23.1k1 gold badge14 silver badges22 bronze badges
add a comment |
add a comment |
In git the default branch is master
.
When you commit git will "use" the current branch which you on right now.
Since you have initialized a new repository you are on the "default" branch and this is why you don't see it in your branches list, it will show up once you commit your changes.
I understand branching, I don't understand why "git status" says I'm on a branch that doesn't exist.
– GOVarney
yesterday
add a comment |
In git the default branch is master
.
When you commit git will "use" the current branch which you on right now.
Since you have initialized a new repository you are on the "default" branch and this is why you don't see it in your branches list, it will show up once you commit your changes.
I understand branching, I don't understand why "git status" says I'm on a branch that doesn't exist.
– GOVarney
yesterday
add a comment |
In git the default branch is master
.
When you commit git will "use" the current branch which you on right now.
Since you have initialized a new repository you are on the "default" branch and this is why you don't see it in your branches list, it will show up once you commit your changes.
In git the default branch is master
.
When you commit git will "use" the current branch which you on right now.
Since you have initialized a new repository you are on the "default" branch and this is why you don't see it in your branches list, it will show up once you commit your changes.
answered yesterday
CodeWizardCodeWizard
59.9k12 gold badges78 silver badges102 bronze badges
59.9k12 gold badges78 silver badges102 bronze badges
I understand branching, I don't understand why "git status" says I'm on a branch that doesn't exist.
– GOVarney
yesterday
add a comment |
I understand branching, I don't understand why "git status" says I'm on a branch that doesn't exist.
– GOVarney
yesterday
I understand branching, I don't understand why "git status" says I'm on a branch that doesn't exist.
– GOVarney
yesterday
I understand branching, I don't understand why "git status" says I'm on a branch that doesn't exist.
– GOVarney
yesterday
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f57051056%2fwhy-does-git-status-show-im-on-the-master-branch-and-git-branch-does-not-in%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown