Git is a distributed version control system so it allows you to create branches locally and commit against them. It also supports a more centralized repository model. When using a centralized repository you can push changes to it so that others can pull them more easily. I have a tendency to work on multiple computers. Because of this, I like to use a centralized repository to track the branches as I work on them. That way no matter what machine I'm on, I can still get at my branches.
My workflow is generally something like this:
- Create a remote branch
- Create a local branch that tracks it
- Work, Test, Commit (repeat) - this is all local
- Push (pushes commits to the remote repository)
Git commands can be a bit esoteric at times and I can't always seem to remember how to create a remote git branch and then start working on new code. There also seems to be multiple ways of doing it. I'm documenting the way that seem to work for me so that I can remember it. Maybe it will help someone else too.
Creating a Remote Branch
Create the remote branch
Make sure everything is up-to-date
Then you can see that the branch is created.
This should show 'origin/new_feature_name'
- Start tracking the new branch
This means that when you do pulls that it will get the latest from that branch as well.
- Make sure everything is up-to-date
Cleaning up Mistakes
If you make a mistake you can always delete the remote branch (Ok Git'ers - that has to be the least intuitive command ever.)
Use the Branch from Another Location
When you get to another computer or clone the git repository to a new computer, then you just need to start tracking the new branch again. to show all the remote branches to start tracking the new branch
Automate it A Bit
That's a pretty easy thing to automate with a small shell script luckily
For further help, you might want to check out:
- Pragmatic Version Control Using Git (Pragmatic Starter Kit)
- Version Control with Git: Powerful tools and techniques for collaborative software development
- Pro Git