1

Hi I am new to Git and I am trying to do these simple steps.

  1. First I clone my remote repo from GitHub

    git clone git@github.com:eldon/Test.git
    
  2. Then I make some changes in a file and try to stage it to commit

    git add *
    
  3. Then I commit it:

    git commit -m "Initial Commit"
    
  4. Then I push it:

    git push origin master
    

But then if I check git status it is showing head detached . If I give the below code its working fine:

git checkout master

Sometimes it is showing head detached after I commit also.

What is the reason for this behavior?

Scott Weldon
  • 9,673
  • 6
  • 48
  • 67

1 Answers1

1

It looks like your local branch is not tracking your remote branch, because you cloned an empty repository with no original content and no master branch.

When you push the first time you should use the following command.

git push -u origin master
merlin2011
  • 71,677
  • 44
  • 195
  • 329
  • what does '-u' indicates in the git push – Eldon Kuzhyelil Jan 04 '17 at 05:43
  • @EldonKuzhyelil, In this case, the flag is equivalent to `--set-upstream` which basically tells git that the local branch should track the remote branch so that in the future you can just `git push` and `git pull` without specifying a remote explicitly. – merlin2011 Jan 04 '17 at 06:48