17

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?

2 Answers 2

17

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.

1
  • better than x number of "tutorials" which take a simple process and make it complex.
    – Thufir
    Aug 9, 2012 at 5:34
9

I find this a valuable resource: A Successful Git Branching Model

Unlike SVN, git is decentralized. You shouldn't ever need to push unstable code to your client's repository. You can simply pull the unstable code to your 2nd computer from the 1st.

Having said that, git handles branching great and should be an integral part of whatever methodology you end up using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.