AgostinoX
AgostinoX

Reputation: 7683

git, understand local repository when multiple branches

I had a ruby on rails project, after a while i decided to put it under git, so i change the directory to the project root and i issued a

git init

command. Then i pushed it onto my bitbucket git repository.

The effect of git init has been to have a .git directory created inside my project, and i've understood that this is the local git repository.
Now i want to branch my project to add some feature.

My first idea is to create another project directory for the branch, so that is possible to work on the 'master' or on the 'new_feature_x' branch the same.

But what about the git repository inside my master branch?

Am I supposed to create another directory with another local git repository?
Shouldn't the local repository be shared among the different branches of a project?

Upvotes: 0

Views: 126

Answers (1)

user456814
user456814

Reputation:

The .git directory is independent of your working copy, it will not be affected by any normal branching, committing, and merging operations you do with Git. You can still work on both your master branch and a feature branch at the same time.

To make your feature branch and check it out into your working copy directory, use

git checkout -b <feature branch name> master

Then you can switch between master and feature as much as you want:

git checkout master
git checkout feature

Upvotes: 2

Related Questions