Git 1.5.3 : submodule

Here’s another new functionality introduce in Git 1.5.3 : submodule.

Submodules allows you to manage subparts of a project in different git repositories and reference them in a “superproject” repository.

You can see it as an equivalent to Subversion “externals”.

A simple usage exemple (in your “superproject” root) :

git submodule add http://mygitdomain.tld/my_sub_project
git submodule init
git submodule update
  1. This will add the remote my_sub_project as an entry in .gitmodules and a directory named my_sub_project in your “superproject”.
  2. Then initialize all modules added, this means add them to .git/config
  3. And finally clone and checkout the different modules in their respective directories (created by the git submodule add command)

[Update – 2007/12/05]

I forgot to add you should not work directly with the “superproject” git repository besides adding more submodules.

You should clone the “superproject” git repository first and then the submodule part will be usable.

git clone superproject superprojectcloned
cd superprojectcloned
git submodule init
git submodule update

and work from “superprojectcloned” repository.

Then when you want to include the last versions of the submodules, issue :

git submodule status
git submodule update
  1. status, gives you an overview of the submodules state.
  2. update, fetch the latest version and reference the sha1 associated.[…]
Published on Sat, 15 Sep 2007 19:31
5 comments

Git 1.5.3 : stash

I installed this monday Git 1.5.3 and discovered a new functionality I find worth sharing : stash.

Basically, stash grab your current uncommitted changes and put them away until you want to reapply them. Git documentation for git-stash lists two examples where this comes in handy :

  1. Pulling into a dirty tree
I’m sure you already had the nightmare it is that you started working on a new functionality when a change you need appears in the upstream repository. Your current changes conflicting with the upstream’s ones git pull does not work. Here come the stash, simply issue a git stash (or git-stash, with an optional description message as you can have multiple stashes), then git pull to include the upstream changes and finally git stash apply to re-integrate your latest stashed modifications.
  1. Interrupted workflow (this one talk to me so much)
You’re working hard on some new kick-ass features when someone (your boss / client) come in and want this immediate fix in what it call a critical bug. One solution is to commit your changes to a new branch, correct the fix, commit it, rebase the new branch to the head with the fix, and then merge back the changes. I’m sure you already see the power of stash in such cases. No more in a hurry branches and commits, simply stash your changes, correct the bug, and reapply the stashed changes.[…]
Published on Tue, 04 Sep 2007 14:57
0 comments

RSS