Dariusz on Software Quality

04/10/2008

Git Version Control System usage techniques

Filed under: en — Tags: — dariusz.cieslak @

We (Aplikacja.info) are a small Polish software company that write mostly in Python language and use Linux for development. GIT is an advanced version control system that was created by Linux Torvalds for maintain Linux kernel source tree. I’ll show how git can be connected in Unix shell environment with make tool.

Why GIT have been chosen to support our version control needs?

  • Failure in development server will not block our work
  • Access to history is very fast (it’s stored on every working copy)
  • I used to work during flight, GIT supports all VCS operations off-line (commit, diff, etc.)

The hard thing about GIT is that it may confuse beginners. If you are one, remember:

  • Always use git diff HEAD instead of git diff
  • Always using git commit -a instead of git commit

Some of this gotchas have been addressed by some GIT interfaces, but they are deprecated now.

In order to ease GIT (and earlier, CVS) usage we introduced additional Makefile targets that handle typical source control tasks.

Examining working copy.

make st shows current working copy state with all local branches and current selected branch:

    st:
        git branch
        git status -a | cat

(cat simply remove pager call). make di shows differences between last committed version and working copy:

    di:
        git diff HEAD

Locally stored history (few last commits) can be inspected by make ch:

    ch:
        git log --pretty=oneline -15 | cat

We are using topic branches strategy to develop software, so switching branch (make sb) is a very common operation:

    sb:
        @read -p "name of existing branch to switch to [a-z_0-9]+: "\
            branch_name;\
        git checkout $$branch_name;

Local commits

If we have some changes uncommitted in working copy we can commit them now:

    commit: di st
        git commit -a

Above command shows current changes to be committed (di) and state of a repository (st) then allows to enter comment.

Going remote

Lets synchronise our working copy with central repo (without locally unmodified changes): make sync:

    sync:
        -git pull $(REPO) +`git branch | awk '/^\*/ {print $$2}'`
        git push $(REPO) `git branch | awk '/^\*/ {print $$2}'`

It downloads current branch from central server (this operation can fail when no branch exists yet, so we ignore errors here by “-” character) and pushes un-synced commits made.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress