Keywords: git, pull, branch, HEAD detached, rebase

Issue

When pull first time, there’s an error log:

You are not currently on a branch. Please specify which branch you want to merge with.

Solution:

  1. check all files, stash or revert all changes
    git status
    
  2. switch branch to master
    git checkout master
    
  3. update repository
    git pull
    
  4. swtich branch to customized branch
    git checkout mybranch
    

Origin:
https://blog.csdn.net/whm18322394724/article/details/86063806

HEAD detached while rebase (Branches Merging)

When you rebase your repo to merge branches:

git checkout master
git pull
git checkout my_branch && git rebase master

if there’re some conflicts between master and my_branch, git get HEAD detached automatically, and shell gives you tips:

hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".

To attach my_branch again, either edit the conflicted files and run git rebase --continue, or discard them by running git rebase --skip.


上帝等待着人类在智慧中获得新的童年。──泰戈尔(Rabindranath Tagore)