ArnaudTheDevelopper
ArnaudTheDevelopper

Reputation: 81

Making two branches identical git

Actually, i have two branchs on git. I want them to be identical. However, in the future i want work only on one branch and the changes don't appear on the other branch (branch master is the branch on which i will work and branch V1 is the save).

I did the commands git checkout master and git branch V1.

Do you know if it is sufficient ?

Thanks,

Upvotes: 0

Views: 325

Answers (2)

Arora20
Arora20

Reputation: 1063

Yes, above steps will be sufficient enough With your commands, you first did checkout to the master branch, then git branch branch_name will create a new branch.

To work on the new branch you can again checkout and commit. It won`t affect anything on the master.

Better to git pull master before creating a new branch. In place of git branch V1, you can use

git checkout -b V1

this will create and checkout to a new branch

Upvotes: 2

Maciej Jureczko
Maciej Jureczko

Reputation: 1598

What you did is you obtained a branch V1 that is in the exact state that branch master was when you executed those commands. You "saved" that current state of master into V1.

So short answer: yes it is sufficient for your requirement.

Nevertheless if "saving a state" is what you are doing, you probably don't really need to do that using a new branch. GIT saves the entire history of commits, so at any time you can simply checkout a past commit and get back to the state you were at that time. Just remember to make frequent commits. Also, you can read about tags which will help you mark milestone (for eg. version/release) points during your development.

Also remember to always keep your branches up-to-date before you perform any operations (fetch/pull) unless you specifically do not want that.

Upvotes: 2

Related Questions