-1

Below is what I did while using git. I took a repository from my github account. I check the branches now in my local workspace. I switch to a remote branch like this

git checkout remotes/origin/circular_buffer_modifications

Why my head got detached? Does this mean I switched correctly or there is an error when head gets detached?

When I checkout to another name

git checkout circular_buffer_modifications

I did not get any warnings?

CPU-384U ~/acid/another_tests_github_personal/BTB: git clone https://github.com/mrigendrachaubey/back_to_basics.git
Cloning into 'back_to_basics'...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 9 (delta 2), reused 9 (delta 2), pack-reused 0
Unpacking objects: 100% (9/9), done.
Checking connectivity... done.
CPU-384U ~/acid/another_tests_github_personal/BTB: ls
back_to_basics
CPU-384U ~/acid/another_tests_github_personal/BTB: cd back_to_basics/
CPU-384U ~/acid/another_tests_github_personal/BTB/back_to_basics: git remote -v
origin  https://github.com/mrigendrachaubey/back_to_basics.git (fetch)
origin  https://github.com/mrigendrachaubey/back_to_basics.git (push)
CPU-384U ~/acid/another_tests_github_personal/BTB/back_to_basics: git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/circular_buffer_modifications
  remotes/origin/master
  remotes/origin/modified
CPU-384U ~/acid/another_tests_github_personal/BTB/back_to_basics: git checkout remotes/origin/circular_buffer_modifications
Note: checking out 'remotes/origin/circular_buffer_modifications'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at df66963... [BTB_CB] Added macro MAX
CPU-384U ~/acid/another_tests_github_personal/BTB/back_to_basics: git branch
* (HEAD detached at origin/circular_buffer_modifications)
  master
CPU-384U ~/acid/another_tests_github_personal/BTB/back_to_basics: git checkout circular_buffer_modifications
Branch circular_buffer_modifications set up to track remote branch circular_buffer_modifications from origin.
Switched to a new branch 'circular_buffer_modifications'
CPU-384U ~/acid/another_tests_github_personal/BTB/back_to_basics: git branch
* circular_buffer_modifications
  master
CPU-384U ~/acid/another_tests_github_personal/BTB/back_to_basics: git branch -a
* circular_buffer_modifications
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/circular_buffer_modifications
  remotes/origin/master
  remotes/origin/modified
CPU-384U ~/acid/another_tests_github_personal/BTB/back_to_basics: 

I think these are very basics of git which I do not understand. Can anyone tell me what kind of thought process I should follow when I,

  1. Create a new branch to remote from local workspace using command line

  2. Create a new branch to remote from github webpage?

  3. what is a local branch, how does or how can it refer to a remote branch, so that I can push code only to the correct remote branch.

  4. What is HEAD, origin? Like 'origin' is the 'originating place' of code. That originating place is always a remote. Am i right in understanding the term?

I can go to the documentation of git, but I don't think documentations ever helped me in knowing particular questions, because I understand git in a broken way as sometimes the terms does not make me give inherent understanding.

1 Answers1

2

Why my head got detached? Does this mean I switched correctly or there is an error when head gets detached?

Because you must switch to a local branch (not a remote tracking one) for your HEAD to be considered as "not detached".

When I checkout to another name git checkout circular_buffer_modifications I did not get any warnings?

See git checkout man page:

If <branch> is not found but there does exist a tracking branch in exactly one remote (call it <remote>) with a matching name, treat as equivalent to

$ git checkout -b <branch> --track <remote>/<branch>
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • May I ask how this question is not overly broad? – Tim Biegeleisen Dec 15 '18 at 08:15
  • @VonC I got clarity with your input. For the rest I am using references and documentation. – android_noob_xx Dec 15 '18 at 08:36
  • @TimBiegeleisen I understand its a broad question, thats why i have kept point like 1, 2, 3, 4. You need not give an absolute answer, but any answer makes me understand how it works. – android_noob_xx Dec 15 '18 at 08:37
  • 1
    @android_noob_xx on what is HEAD: https://stackoverflow.com/a/3690796/6309 and https://stackoverflow.com/a/964927/6309. On origin, as an illustration: https://stackoverflow.com/a/9257901/6309 – VonC Dec 15 '18 at 20:31