Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens to my local project files when I create a new git branch?

Tags:

git

branch

merge

Suppose I have a repository on my local machine, a working directory where I make changes and push to remotes, and I decide I would like to add a new feature which will in time replace an in place feature.

What happens when I create a new branch and start modifying my working directory? If I switch to the new branch and start making changes, those changes are overwriting code on my local machine, are they not?

So if I have two branches, one Master and one NewFeature, how can I maintain copies of both on my local machine up until I decide merging is ready?

How is this normally done?

like image 549
ebd Avatar asked Oct 25 '25 05:10

ebd


1 Answers

You have a folder on the repo with the name .git, this folder contains all the information that is necessary for your project in version control and all the information about commits, remote repository address etc. all are present in this folder. It also contains a log which stores your commit history so that you can roll back to history.

When you working on Master branch, on your local folder you have the files of the Master branch.

When you run the command git checkout NewFeature and in this branch have any changes from Master branch, you local folder will be overwriting the Master with NewFeature changes.

But you do not lose your Master branch content, it saves on .git folder, when you will go back to the Master your local folder will be changed again.

So - you don't have yo maintain your 2 branches, GIT does it for you.

like image 163
Shayki Abramczyk Avatar answered Oct 26 '25 19:10

Shayki Abramczyk