⊗gtPmBrSw 37 of 65 menu

Switching Branches in Git

Now let's learn how to switch between branches. To do this, use the checkout command, followed by the branch name. Let's switch to the test branch we created in the previous lesson:

git checkout test

You can also use the synonym switch:

git switch test

After executing any of the two commands above, a message will appear in the terminal about switching to the specified branch:

Switched to branch 'test'

When switching from branch to branch, files in the Git working directory also change. That is, files from one branch will physically disappear and files from another branch will appear. Pay attention to this, as it is not very obvious for Git newbies.

It turns out that in Git all changes in branches are isolated from each other and you can easily and quickly create several branches of a project without introducing confusion into the original version.

Switch to the new branch. While in this branch, make changes to the file, stage them and commit. Then switch to the main branch and check the contents of the file - it should return to the original version.

Switch to the new branch. While on this branch, create a new file, stage it, and commit it. Then switch to the main branch and see that the new file disappears. Switch back to the new branch and see that your file comes back.

English
БеларускаяDeutschEspañolFrançaisPortuguêsРусский
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline