My Goal : Make a successful checkout without detached HEAD error.
What I have done so far : Currently I have two remotes setup :
origin : It points to a repo of a course I am currently learning.
fsprojects: It points to my personal repo.
$ git remote
fsprojects
origin
$ git remote show fsprojects
* remote fsprojects
Fetch URL: https://github.com/fs-projects/core-concepts-nextjs.git
Push URL: https://github.com/fs-projects/core-concepts-nextjs.git
HEAD branch: events-projects-finsih
Remote branches:
client-and-serverside-fetching-useswr tracked
events-project-data-fetching-pre-rendering tracked
events-projects-finsih tracked
nextjs-optimisations tracked
project-api-routes tracked
ssg-functions tracked
writing-api-in-same-server-and-leveraging-from-server-and-client tracked
Local branch configured for 'git pull':
project-api-routes merges with remote project-api-routes
Local ref configured for 'git push':
project-api-routes pushes to project-api-routes (up to date)
I checked out a commit in remote "origin" so I entered into a detached HEAD state(which is as expected). I did some new changes in the detached HEAD state and created a new branch project-api-routes from that point.
I now setup this branch to track remote branch with same name located in fsprojects/projects-api-routes using this command -
git branch -u fsprojects/project-api-routes
git status
output :
$ git status
On branch project-api-routes
Your branch is up to date with 'fsprojects/project-api-routes'.
nothing to commit, working tree clean
Now when I checkout to any branch belonging to either remotes origin or fsprojects with below command
git checkout remotes/fsprojects/events-projects-finsih
I get below error :
$ git checkout remotes/fsprojects/events-projects-finsih
Note: switching to 'remotes/fsprojects/events-projects-finsih'.
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 switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 539cfbe All events projects - finish up all pages
I am not able to understand why I am getting this error despite my source is a branch and not any commit id.
I want to checkout to the destination branch without any detached HEAD error. Any help/guidance to achieve it will be helpful. Thanks in advance!!
Just FYI -
git branch -a
(to see list of all branch that can be checked out) gives below output :
MINGW64 /d/Next.Js/nextjs-course-code ((539cfbe...))
$ git branch -a
* (HEAD detached at fsprojects/events-projects-finsih)
main
project-api-routes
remotes/fsprojects/client-and-serverside-fetching-useswr
remotes/fsprojects/events-project-data-fetching-pre-rendering
remotes/fsprojects/events-projects-finsih
remotes/fsprojects/nextjs-optimisations
remotes/fsprojects/project-api-routes
remotes/fsprojects/ssg-functions
remotes/fsprojects/writing-api-in-same-server-and-leveraging-from-server-and-client
remotes/origin/01-getting-started
remotes/origin/01-getting-started-extra-files
remotes/origin/02-file-based-routing
remotes/origin/02-file-based-routing-extra-files
remotes/origin/03-prj-routing
remotes/origin/03-prj-routing-extra-files
remotes/origin/04-data-fetching
remotes/origin/04-data-fetching-extra-files
remotes/origin/05-prj-data-fetching
remotes/origin/06-optimizations
remotes/origin/07-api-routes
remotes/origin/07-api-routes-extra-files
remotes/origin/08-prj-api-routes
remotes/origin/08-prj-api-routes-extra-files
remotes/origin/09-context
remotes/origin/09-context-extra-files
remotes/origin/10-prj-blog
remotes/origin/10-prj-blog-extra-files
remotes/origin/11-deployment
remotes/origin/11-deployment-extra-files
remotes/origin/11-deployment-static
remotes/origin/12-auth
remotes/origin/12-auth-extra-files
remotes/origin/HEAD -> origin/main
remotes/origin/empty
remotes/origin/main
remotes/origin/starting-prj
remotes/origin/zz-nextjs-summary
remotes/origin/zz-nextjs-summary-extra-files
remotes/origin/zz-prj-nextjs-summary
remotes/origin/zz-prj-react-summary
remotes/origin/zz-react-summary
remotes/origin/zz-react-summary-extra-files