Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Add some smarts to your git workflow
Ruby
branch: smart-merge

This branch is 87 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bin
lib
spec
.gitignore
Gemfile
Gemfile.lock
LICENSE.txt
README.md
Rakefile
VERSION
git-smart.gemspec

README.md

git-smart

Adds some additional git commands to add some smarts to your workflow. These commands follow a few guidelines:

  1. It should do the 'right thing' in all situations - an inexperienced git user should be guided away from making simple mistakes.
  2. It should make every attempt to explain to the user what decisions it has made, and why.
  3. 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.
  4. All git commands, destructive or not, and their output should be shown to the user with the -v/--verbose flag.

Installing

First, grab the gem:

gem install git-smart

List the commands you can install (currently only the one):

git-smart list

Install away!

git-smart install smart-pull

OR

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.

Using

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:

git smart-pull

git-smart-pull

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:

  1. 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'.
  2. Fetch the remote.
  3. 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:
      1. stash
      2. rebase -p onto the remote
      3. stash pop
      4. update ORIG_HEAD to be the previous local HEAD, as expected (rebase -p doesn't set ORIG_HEAD correctly)
  4. 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

Copyright (c) 2011 Glen Maddern. See LICENSE.txt for further details.

Something went wrong with that request. Please try again.