Mike Pearce – blog

git status on multiple repos

Posted in Code, git, Python by Mike Pearce on June 16, 2010
Show_status

git status is now better

Often a lot of the work I do is on services. This means that, in any given day, I’ll perhaps be working on one or more repos. As is the way of git, I commit often to the local working branch and they push to the master at the end of the day, or whenever I’ve got feature, or patch of fix or whatever that needs to go back upstream. First thing in the morning, I’ll also do a pull for each repo I’m going to work on, including dependent repos.

If you’ve got a lot or repos, this quickly gets tedious to cd into each directory, run git status, then git push or git pull, cd back out, then into the next directory, etc etc.

So, I wrote a wee python script called ‘show_status’

Usage: show_status [options]

Show Status is awesome. If you tell it a directory to look in, it'll scan
through all the sub dirs looking for a .git directory. When it finds one it'll
look to see if there are any changes and let you know. It can also push and
pull to/from a remote location (like github.com) (but only if there are no
changes.) Contact mike@mikepearce.net for any support.

Options:
  -h, --help            show this help message and exit
  -d DIRNAME, --dir=DIRNAME
                        The directory to parse sub dirs from
  -v, --verbose         Show the full detail of git status
  -r REMOTE, --remote=REMOTE
                        Push to the master (remotename:branchname)
  -p PULL, --pull=PULL  Pull from the master (remotename:branchname)

Just running ‘show_status’ will always run a non-verbose check on any sub dirs in your current dir, so:

%> show_status
-- Starting git status...
Scanning sub directories of /home/sites/
--/home/sites/gitstatus        : No Changes
--/home/sites/projectone    : No Changes
--/home/sites/project2        : No Changes
Done

You can also pass in a directory that you want to use, this is useful if you wanted to use it in other scripts, or if you’re not in a root directory:

%> show_status -d/home/sites

You can add a pull request, which will pull from a remote master. It’s important to note that it’ll only pull from a remote master if there are no local changes waiting to be committed. This is to force you to manage your merges carefully.

%> show_status -pmikepearce:master

Finally, you can do push requests as well, again, this will only work on repos where there is nothing waiting to be commited:

%> show_status -rmikepearce:master

You can grab the whole thing on github (Git Status), or just clone/fork here: git@github.com:MikePearce/Git-Status.git

Tagged with: , , ,

A little bit of git

Posted in git by Mike Pearce on June 1, 2010

Using git after SVN is like driving a Ferrari after driving a Jaguar. Nimble, speedy, lovely. My word it’s beautiful.

Anyway, I’m learning my way around it and, recently, came across these two lovely things:

Colouring the git output (from @catchamonkey)

I didn’t realise how useful colouring the output of things like git diff and git status etc was until I’d done it. Follow the below:

%> vi ~/.gitconfig

This will open the global .gitconfig file for your CURRENT user in vi. It will probably look something like this:

[user]
 name = Mike Pearce
 email = mike.pearce@jellyfish.co.uk

Below all that, you’ll need to add this:

[color]
        ui = auto
[color "branch"]
        current = yellow reverse
        local = yellow
        remote = green
[color "diff"]
        meta = yellow bold
        frag = magenta bold
        old = red bold
        new = green bold
[color "status"]
        added = yellow
        changed = green
        untracked = cyan

Obviously, you can change the colours to suit your particular pallete, but the above are pretty cool!

Global Ignorance (via @nefarioustim)

Sometimes, you’ll want to ignore the same file for each git repo. You can add the ignored files to the git repo itself, or, if you know there’ll always be a file or files you want to ignore, you can add it to git excludes.

I use netbeans on a mac, so I generally ignore the following:

  • .DS_Store
  • ./nbproject
  • *.pc (compiled python code)

You can do it by editing the .gitconfig file again:

%> vi ~/.gitconfig

Then adding the following lines somewhere:

[core]
 excludesfile = ~/.gitexcludes

OK, save then, then do this:

%> vi ~/.gitexcludes

and add each one on a new line:

DS_Store
nbproject
*.pc

Save that et voila. You’ll never be troubled with those files being added to your repo again.

Tagged with: , , , ,
Follow

Get every new post delivered to your Inbox.

Join 912 other followers