Understanding GIT branches is a little better

I am new to version control and I have a question about branching. I have the following branches: "dev" and "master" Let's say I add or modify a file in dev, I run "git status" and it shows what I changed. Now, if I switch to the "master" branch, I also see pending changes when I run "git status". Should it be right? However, as soon as I run "git commit ...", I will receive commit messages related to the specific branch I went through.

I thought and hoped that each branch would be different. It seems like it is, but I see where I can get confused if I commit the wrong branch when I switch back and forth.

+3
source share
2 answers

Now, if I switch to the "master" branch, I also see pending changes when I run "git status". Should it be right?

Yes. You have not made any changes yet. Git allows you to start working with files when one branch is checked, and then (prohibiting any conflicts) switches to another branch before committing so that you can commit changes to that branch instead.

+5
source

In Git Magic , Ben Lynn seems to recommend that you do git commit -abefore switching branches for this very reason.

You can use git stashto save changes without committing.

+3
source

Source: https://habr.com/ru/post/1735271/


All Articles