Volomike
Volomike

Reputation: 24896

Creating a branch in git, but nervous about harming existing stable master

I have a precious install on my hard drive:

/var/www/lukevan/po2/po

This is the "PO" project. We wish to maintain that version for our customers, but now we need to do a new, experimental branch that may be unstable for awhile until we are ready to merge that back into the live, current, stable PO project. I have reviewed this documentation, but what confuses me is whether I should run this in my precious /var/www/lukevan/po2/po folder, or whether I should do something else so as not to risk hurting my precious /var/www/lukevan/po2/po folder?

Upvotes: 1

Views: 74

Answers (5)

Volomike
Volomike

Reputation: 24896

Here's what I did, although I don't know if it's the most optimal way to handle this:

On my development workstation, which has a web server:

cd /var/www/lukevan
mkdir pof2
cd pof2
git clone [email protected]:po.git
ls
# a po folder was listed -- that's the MASTER of our project, called "po".
git branch pof2
git checkout pof2

I can now work on /var/www/lukevan/po2/po to work on the stable master branch when necessary, and then work on /var/www/lukevan/pof2/po to work on the unstable, experimental branch when necessary too. I can run my "git pull origin master" or "git pull origin pof2" to download most recent files, hack away, then run git add ., then run git commit -m "what I'm committing", and then git push origin master for master and git push origin pof2 for pof2.

Upvotes: 0

ralphtheninja
ralphtheninja

Reputation: 133068

Git is not mercurial. There's absolutely no need to re-clone this repository. This is what branches were made for, i.e. give you the possibility to create a seam where you can work in isolation not needing to worry about making changes to some other branch. Just create your new branch and start hacking and commiting.

git checkout -b experimental
// hack hack hack
git add foo
git commit -m 'changed foo'

Now the files in /var/www/lukevan/po2/po have changed on the experimental branch, they haven't changed the ones on the master branch. When you switch back to master, the files will be checked out according to how they look on the master branch.

Cloning is an expensive operation. Creating a branch is only a 41 bytes file overhead and is super fast and light weight. Git rules when it comes to branching. Use it ! :)

Upvotes: 0

Mark
Mark

Reputation: 6128

Make a clone of your "precious" folder and then create the branch in the clone. If something goes horribly wrong you can just start using the original repo.

Actually this is the whole point of using a version control system, but sometimes it doesn't hurt to be a bit paranoid.

Upvotes: 0

Chris Ledet
Chris Ledet

Reputation: 11628

One of the benefits of a version control system is the ability to revert your changes. Don't worry yourself too much about it.

Upvotes: 0

Colin Hebert
Colin Hebert

Reputation: 93177

In your case, you should clone your repo somewhere safe and work on the clone.

This way your work won't impact the working directory of the original repo.

Upvotes: 1

Related Questions