TIL git switch
POSTED ON:
TAGS: git
These two commands replaces two common uses of git checkout.
git switch
to switch to a new branch after creating it if necessary
git switch my-branch # same as git checkout my-branch
git switch -c my-branch # same as git checkout -b my-branch
git switch -c my-branch HEAD~3 # branch off HEAD~3
git switch --detach HEAD~3 # checkout commit without branching
git restore
to restore changes from a given commit.
git restore --source HEAD~3 main.c # --worktree is implied
rm -f hello.c
git restore hello.c
git restore '*.c'
git restore --staged hello.c # same as using git reset
git restore --source=HEAD --staged --worktree hello.c # same as git checkout
Related TILs
Tagged: git