0

I have a branch testbranch created from master via GIT GUI. Currently I am on master on GIT command line.

when I say "git branch -b testbranch" and "git checkout testbranch" , it says it switched to the testbranch but the files are not updated. I don't know why this strange behavior.

Also what is difference between git branch testbranch and git branch -b testbranch.

mike
  • 1,233
  • 1
  • 15
  • 36
Stunner
  • 961
  • 2
  • 19
  • 39

2 Answers2

2

That is why the old obsolete and confusing git checkout command has been replaced by:

In your case, if the files are not correctly updated after a checkout, you can force them with:

git restore --source=HEAD --staged --worktree hello.c

(assuming you don't have any work in progress)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
-3

I have found out the answer.

I just did below. Simple.

rm -rf reporsitory
git clone repository
git checkout testbranch.

It worked.!

Git is supposed to make life simple.. But it is making it complex instead with ambiguous keywords and commands. Why the hell on the earth can't we clone only a branch rather than the whole repo. And why do we have two seperate commands to switch the branch and checkout the branch.

Stunner
  • 961
  • 2
  • 19
  • 39
  • 1
    So... the xkcd approach (https://xkcd.com/1597/). I like it. – VonC Aug 24 '20 at 06:45
  • @Thanks for sharing the pic.. true story :) – Stunner Aug 24 '20 at 08:13
  • 1
    Sorry, but I gotta downvote you. Git is confusing and sometimes a workaround helps, but providing it as the "answer" as to why things didn't really work is problematic because it just perpetuates the problem. – Joachim Sauer Aug 24 '20 at 10:33