0

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
  • 1
    no. [Documentation](https://git-scm.com/docs/git-switch) do not suggest anything related to remotes. Please learn to inspect doc. – Marek R Jan 20 '23 at 14:41
  • As I understand it switches simply to that branch. Is your local branch behind the remote branch nothing will be pulled – Jens Jan 20 '23 at 14:43
  • Should I do a `git pull` after doing a `git switch` to make sure I have all the changes from remote – juan Jan 20 '23 at 14:47
  • @Jens What if I cloned a new repository and do a git switch. Does only the metadata from the remote is pulled locally? – juan Jan 20 '23 at 14:52
  • @juan: the data will be pulled, if you do a `git fetch` already. But you can try it and/or read the documentation – Jens Jan 20 '23 at 14:54

1 Answers1

1

TL;DR

No!

Switch Branch

  1. all files that have been changed in your initial branch will be taken to the new branch.
  2. all files that you have already committed in your original branch will not be taken along. However, you can then pull in the commit in the source branch.

As long as you make your commits and branch changes locally, your remote remains unaffected. Only with a git push are your "committed" changes transferred to the remote. Before that, however, you must first perform a git merge in your source branch so that the changes take effect.

Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79