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;








41















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.










share|improve this question






























    41















    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.










    share|improve this question


























      41












      41








      41


      1






      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.










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      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






















          5 Answers
          5






          active

          oldest

          votes


















          50














          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.






          share|improve this answer


















          • 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 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



















          11














          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.






          share|improve this answer


















          • 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


















          6














          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.






          share|improve this answer
































            5














            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)






            share|improve this answer






























              0














              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.



              enter image description here



              enter image description here






              share|improve this answer























              • I understand branching, I don't understand why "git status" says I'm on a branch that doesn't exist.

                – GOVarney
                yesterday













              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
              );



              );













              draft saved

              draft discarded


















              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









              50














              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.






              share|improve this answer


















              • 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 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
















              50














              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.






              share|improve this answer


















              • 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 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














              50












              50








              50







              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.






              share|improve this answer













              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.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              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 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













              • 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 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








              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














              11














              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.






              share|improve this answer


















              • 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















              11














              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.






              share|improve this answer


















              • 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













              11












              11








              11







              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.






              share|improve this answer













              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.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              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












              • 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











              6














              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.






              share|improve this answer





























                6














                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.






                share|improve this answer



























                  6












                  6








                  6







                  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.






                  share|improve this answer















                  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.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 16 hours ago

























                  answered yesterday









                  MrTuxMrTux

                  22.5k15 gold badges63 silver badges100 bronze badges




                  22.5k15 gold badges63 silver badges100 bronze badges





















                      5














                      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)






                      share|improve this answer



























                        5














                        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)






                        share|improve this answer

























                          5












                          5








                          5







                          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)






                          share|improve this answer













                          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)







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered yesterday









                          Mark AdelsbergerMark Adelsberger

                          23.1k1 gold badge14 silver badges22 bronze badges




                          23.1k1 gold badge14 silver badges22 bronze badges





















                              0














                              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.



                              enter image description here



                              enter image description here






                              share|improve this answer























                              • I understand branching, I don't understand why "git status" says I'm on a branch that doesn't exist.

                                – GOVarney
                                yesterday















                              0














                              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.



                              enter image description here



                              enter image description here






                              share|improve this answer























                              • I understand branching, I don't understand why "git status" says I'm on a branch that doesn't exist.

                                – GOVarney
                                yesterday













                              0












                              0








                              0







                              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.



                              enter image description here



                              enter image description here






                              share|improve this answer













                              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.



                              enter image description here



                              enter image description here







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              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

















                              • 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

















                              draft saved

                              draft discarded
















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                              Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                              199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單