Adds some additional git commands to add some smarts to your workflow. These commands follow a few guidelines:
- It should do the 'right thing' in all situations - an inexperienced git user should be guided away from making simple mistakes.
- It should make every attempt to explain to the user what decisions it has made, and why.
- All git commands that modify the repository should be shown to the user - hopefully this helps the user eventually learn the underlying git commands, and when they're relevant.
- All git commands, destructive or not, and their output should be shown to the user with the -v/--verbose flag.
First, grab the gem:
gem install git-smart
List the commands you can install (currently only the one):
git-smart install smart-pull
git-smart install --all
That'll put an executable file for each command in your ~/bin directory if that exists and is on the path, /usr/local/bin otherwise.
Git allows custom commands with a simple convention -
git xyz tries to find an executable
git-xyz on the path. So, to run the smart-pull command, simply run:
Calling 'git smart-pull' will fetch remote tracked changes and reapply your work on top of it. It's like a much, much smarter version of 'git pull --rebase'.
For some background as to why this is needed, see my blog post about the perils of rebasing merge commits
This is how it works:
- First, determine which remote branch to update from. Use branch tracking config if present, otherwise default to a remote of 'origin' and the same branch name. E.g. 'branchX', by default, tracks 'origin/branchX'.
- Fetch the remote.
- Determine what needs to be done:
- If the remote is a parent of HEAD, there's nothing to do.
- If HEAD is a parent of the remote, you simply need to reapply any working changes to the new HEAD. Stash, fast-forward, stash pop.
- If HEAD and the remote have diverged:
- rebase -p onto the remote
- stash pop
- update ORIG_HEAD to be the previous local HEAD, as expected (rebase -p doesn't set ORIG_HEAD correctly)
- Output a big green or red message so, at a glance, you know if things worked or not.
Contributing to git-smart
- Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
- Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
- Fork the project
- Start a feature/bugfix branch
- Commit and push until you are happy with your contribution
- Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
- Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
Copyright (c) 2011 Glen Maddern. See LICENSE.txt for further details.