2

I'm new to using Git and I'm not sure about the current situation.

enter image description here

At the moment, it is in the above state. I've been able to "fetch" from a remote repository and open and run the latest state in my local VS Code, but does that mean that my local HEAD is at f52a6e9a at this point?

If so, I want to bring the local HEAD to the latest point of the main branch, but I don't know how.


2022/7/10/15: 06 Addendum git switch main After executing, the following status is displayed. I think you can now move to the main branch, but at this point the HEAD is at f52a6e9a, right?

enter image description here


Then I executed "git checkout 17d73f6b63ca50e78d3a5a80339b6e8e037cc933". Then, it became the following state.

enter image description here

This is what I want because HEAD is at the latest point of main branch.

As you may have noticed, this is something I'm doing experimentally to study git / Github, and I think I have a lot of basic things to learn.

森口万太郎
  • 805
  • 6
  • 20

1 Answers1

2

Simply check your git status in a terminal (even from VSCode)

That will confirm where HEAD is.

A git switch main would be enough to bring your local repository to that local branch.
From there, a git pull would update it to origin/main if you want.

Avoid git checkout, which is confusing.
And do not checkout a commit, which leads to detached HEAD.

To go to 17d73f6 (the commit or origin/main):

git switch main
git pull
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you for your reply. The result of executing the git status command – 森口万太郎 Jul 10 '22 at 05:52
  • On branch exp Your branch is up to date with 'origin/exp'. – 森口万太郎 Jul 10 '22 at 05:53
  • I believe VonC meant 'git checkout main' not switch – Gec Jul 10 '22 at 05:54
  • Does this mean "I'm in the exp branch at the moment"? In the remote repository, the exp branch has already been merged into the main branch and deleted. – 森口万太郎 Jul 10 '22 at 05:55
  • @Gec Why using the old obsolete checkout command? It is [`git switch`](https://git-scm.com/docs/git-switch), to switch to a branch. Or `git restore`, to restore file. Not `git checkout` [which is confusing](https://stackoverflow.com/a/57066202/6309). – VonC Jul 10 '22 at 05:59
  • @森口万太郎 Yes, you are on exp. `git switch main` will make you go to your expected commit. – VonC Jul 10 '22 at 06:00
  • I added the situation after that to the question. I will investigate the necessary matters based on the answers I received. Thank you for staying with us so far. – 森口万太郎 Jul 10 '22 at 06:23
  • 1
    @森口万太郎 Forget `git checkout`. And a checkout of a commit will leave you in a [detached HEAD state](https://stackoverflow.com/a/3965714/6309). Which is not what you want. Do a `git switch main` again, then `git pull`: you will then be at 17d1. – VonC Jul 10 '22 at 06:24
  • @VonC yes. I stand corrected. Haven't updated git in a long while and I did try the switch before I posted, only to get "git: 'switch' is not a git command. See 'git --help'." Thanks! – Gec Jul 10 '22 at 09:52
  • 1
    @Gec: This means you have an old version of Git (pre-2.23). – torek Jul 11 '22 at 01:14