Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are the Git branches stored?

Tags:

git

branch

github

I'm working on a website and constantly switching from development mode (where the code has every URL in it pointing to localhost, the database is named "project", the user "root", empty password, etc.) to production mode (where everything set to work in my hosting, real passwords, real URLs, etc.) and I just recently started to use Git.

Now, I'd like to make a branch that's for code ready to be uploaded to my hosting, so I don't have to make a copy and manually change everything every time I want to update my website. So, if I make a change in the code and commit in the master branch, it would be reflected in the code for upload without changing other stuff.

So it would be:

Master -> ReadyForUpload

So my question is, when using Git, is each branch stored in physical storage like a directory with every file in it? Is it possible to export a branch to a directory?

I'm using Git extensions for Windows, by the way.

like image 568
federico-t Avatar asked Nov 30 '12 08:11

federico-t


2 Answers

No. Some other version control systems (eg Subversion) stores branches as subdirectories. In git you have one working area and change which branch you works on within that,

eg.

git branch ReadyForUpload
git checkout ReadyForUpload 

Nothing seems to change, but you are now working in the ReadyForUpload branch.

if you then do some changes and commit them and you do a

git checkout Master

you will be back on the masterbranch and the changes in ReadyForUpload are gone (that is, just stored away)

Of course, if you for some reason prefer to have both branches available at the same time, you can clone your repository to another directory and have the other branch checked out there - using git pull or git push to sync them where applicable.

like image 99
MortenSickel Avatar answered Sep 22 '22 12:09

MortenSickel


is each branch stored in physical storage like a directory with every file in it?

The answer to that is no!

Is it possible to export a branch to a directory?

Yes. There are several ways to do an export. but if you intend to do small modifications/investigations on that branch and often would like to work on that branch as disturbing production issues shows up along side with your development (in master branch). I suggest you make another clone from the origin

For example if your centrally agreed upon origin is is git://github.com/my_org/my_proj.git

you would probably have the development WD cloned with

git clone git://github.com/my_org/my_proj.git

Then you should have a production

git clone git://github.com/my_org/my_proj.git my_proj_production
cd my_proj_production
git checkout -b release_branch
git push origin release_branch

in my_proj_production you should modify your urls, passwords, etc. to reflect production situation. Then everytime you shall merge things from development (master) to production (release_branch) you shall in my_proj dir make a git push and in my_proj_production dir you shall do

git remote update
git merge origin/master

The first line makes sure you get changes from remote repo to your local HDD (as small files under .git/objects, the second command ensures that the changes you made are merge into your release_branch (and the urls, passwords, etc. will not be reintrduced in your release_branch).

Please comment if you don't (yet) have a central repository and I will adapt the answer to reflect that situation.

like image 39
Jarl Avatar answered Sep 19 '22 12:09

Jarl