Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I translate trunk/branch concepts from Subversion to Git?

So I am not much of a source control expert, I've used Subversion for projects in the past. I have to use Git for a particular project (client supplied Git repo).

My workflow is as such that I will be working on the files from two different computers, and often I need to check in changes that are unstable when I move from place to place so I can continue my work. What then occurs is when, say, the client goes to get the latest version, they will also download the unstable code.

In SVN, you can address this by creating a trunk and use working branches, or use the trunk as the working version and create stable branches.

What is the equivalent concept in Git, and is there a simple way to do this via GitHub?

like image 336
M. Ryan Avatar asked May 14 '10 19:05

M. Ryan


1 Answers

There are a lot of different ways to do this. If you have to move from computer to computer, you'll be switching to a different repository, so that means you'd be pushing up your changes to the remote repo. That's fine, but it also means you

A very simple example is to only perform your unstable work on a private branch, and to name it something obvious, e.g. unstable-development. Here's how to do this from scratch. First, let's make a new repo from your client's site, which I'll call "secret-sauce".

$ git clone git://example.com/repositories/secret-sauce.git

You're still on the master branch, the default. Let's make a new branch so that you can commit stuff there instead of on master.

$ git branch unstable
$ git checkout unstable
Switched to branch 'unstable'

Okay. Now let's add some unstable code:

$ touch kablammo.txt
$ git add *
$ git commit -m "Added unstable code."
[master (root-commit) 9428aef] Initial checkin.
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 kablammo.txt

Right now, unstable exists only on your side. Notice that when we cloned, we got a remote repository called origin, which has a corresponding master branch. When your local repository knows about a remote repository's branches, we call that a "tracking branch". You can see all your remote tracking branches with git branch -r:

$ git branch -r
  origin/HEAD -> origin/master
  origin/master

Okay. Let's push our changes back!

$ git push origin unstable

That's it -- our changes now live in the unstable branch on the remote repo. If we want to see what people are up to on the master branch again, we can switch back again with git checkout master.

like image 200
Evan Barkley Avatar answered Oct 23 '22 14:10

Evan Barkley