Questions tagged [git-switch]

Switch to a specified branch.

12 questions
782
votes
8 answers

What's the difference between git switch and git checkout

Git 2.23 introduces a new command git switch -- after reading the docs, it seems pretty much the same as git checkout can someone explain the difference or use case? Two new commands "git switch" and "git restore" are introduced to …
Bastian Venthur
  • 12,515
  • 5
  • 44
  • 78
18
votes
1 answer

What does git checkout still do after git switch got introduced?

As everyone knows, git checkout is a very overloaded command. And I do understand that certain commands got introduced to distribute, e.g. to git switch. Before I used the following commands: $ git checkout $ git checkout $…
HelloWorld
  • 2,392
  • 3
  • 31
  • 68
3
votes
4 answers

Git: Why I can still switch to a branch after deletion?

I have just noticed that I can still switch back to a branch after deleting it. Here is a particular example that I have: git switch master git branch -d AB-10/add_flights ... // deleting also the remote branch on GitHub git switch…
Moyshe Zuchmir
  • 1,522
  • 12
  • 18
2
votes
1 answer

How to switch to the Nth previous unique branch in Git?

Lets say I have 3 branches in my repository: main, develop and feature. Now, suppose I have switched my working branch in the following order: from main, to develop, to feature, back to develop, and to feature again. From this position I would like…
Robin Bastiaan
  • 572
  • 2
  • 8
  • 21
1
vote
3 answers

git checkout commit with specific trailer

I have an orphan branch (let's call it output) which contains the documents generated by templates stored on my main branch. I would like to checkout the commit on output that correspond to a specific commit on main. I settled on using git commit…
ITChap
  • 4,057
  • 1
  • 21
  • 46
1
vote
1 answer

Can I retrieve uncommited changes from git after a few known git commands?

I have a local git repo where I did some substantial editing to a file file1.txt. Then I issued a few git commands to look at older versions of this file (and other files). I totally had forgotten that thsi - of course! - would write old veersions…
halloleo
  • 9,216
  • 13
  • 64
  • 122
0
votes
1 answer

Does git switch pull all the changes

When one does git switch branch. Does all the latest changes and files from the remote repository get copied to the local branch? Is it like a replica of remote is created on local and the local and remote both are linked?
juan
  • 47
  • 7
0
votes
1 answer

vscode, auto open/close editors on switching git branches

VSCode shows in the status line which branch of git repository we are in. But switching the branch does nothing to the open editors. My branches are usually working with different set of files and once I switch branches, I have to close all editors,…
White Owl
  • 318
  • 1
  • 8
0
votes
1 answer

What does the dash mean in `git switch -`?

When doing checkout, I got this message: $ git checkout HEAD~2 Note: switching to 'HEAD~2'. You are in a 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state…
Wenfang Du
  • 8,804
  • 9
  • 59
  • 90
0
votes
4 answers

How to switch (or checkout) to a existing remote branch in Git without facing detached HEAD

At first when I clone the Git repository I am in the master branch. But I have already created a remote develop branch. I run git fetch origin develop. Then, I use git checkout develop and it switched to a new branch develop like this: It creates…
Mands
  • 171
  • 1
  • 3
  • 14
-1
votes
1 answer

when there are unstaged changes in a branch or untracked files, in both cases while switching the branches, files get overwritten. How to avoid it?

These steps have been followed to generate the scenario: mkdir testrepo cd testrepo git init touch readme git add readme git commit -m "add readme" git switch -c newbranch touch 1 git switch - Now on master branch I can see 1. Moreover whatever…
-2
votes
1 answer

Does git not highlight the branch name on which we are after we switch to a branch using its case insensitive name

Suppose I am on a branch named main in git and we can confirm it by git branch and git log commands. Screen shot of git bash. But as branch names are case-insensitive in git. So, when we switch to any branch using git switch using its…