Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A set of git commands and hooks, particularly helpful in dealing with github-fork workflows.
Shell
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
hooks
README.md
git-clean-branches
git-current-branch
git-task
git-update

README.md

git-sanity

An extra set of git commands and hooks, particularly helpful in rigid, fork-based, corporate git workflows.

Usage

Simply copy over the scripts you're interested in to somewhere on your $PATH (Some scripts depend on others so make sure you don't omit any needed ones). They can then be invoked without the dash, for example: git update.

Disclaimer

These commands involve stashing and pushing and are potentially dangerous - make sure you read the instructions first; and try to grok the code a little, so you won't be completely helpless if something goes wrong. ;-)

Commands

git update [branch]

Pull the latest changes from master of an upstream repo into any <branch>, then push it to your fork, all without leaving your curent branch. If no <branch> argument is given, the current branch will be updated.

  • Specify which is the upstream remote by doing git config sanity.updatesource <upstream remote name> from within your project, or by adding the following to the bottom of your project's .git/config:

    [sanity]
    updatesource = <upstream remote name>
    

    If no updatesource is specified, it will default to 'upstream'

  • You can also specify the remote your fork is at. This is the remote that will be pushed to after you git update an untracked branch. Set this via git config sanity.remote <your fork's remote name>, or adding this to the [sanity] section in your .git/config:

    remote = <your fork's remote name>
    

    If this is not specified, it defaults to 'origin'; which should be what you want most of the time.

git current-branch

Print the name of the current git branch. A very useful way to use this is to setup a very short bash alias like alias t='git current branch' in your .bash_aliases, so that you can save time by typing commands like git push origin `t`, instead of git push origin 123456_some_feature_description.

git clean-branches

Delete all local branches which have already been merged into master. Prompts before deletion.

git task [-p | --pretty | -l | --link | -o | --open] [branch]

Depends on: git current-branch

At work you probably use some form of bug tracking system and have to name your git feature branches with the corresponding task's number, for example, 123456_some_feature_description, where 123456 is the task ID.

Prints out the task ID based on the branch name, which you can in turn use to open the task's webpage, for example. Supported branch-naming formats are as such, where the task ID is within the <>:

(t|b|bug_|task_|TR-)<1234>(short_description|)  -OR-  (short_description|)_(t|b|bug_|task_|TR-)<1234>

If no branch name is provided, assumes the current one.

Options

-p or --pretty: Print out task number and description based on branchname in a human-readable format. For example, a branchname of new_front_page__t12345 will result in Task: 12345: new front page.

-l or --link: Print out the URL to the task. Beforehand, the URL pattern needs to be configured in your git config with '<>' as a placeholder for the task ID, for example:

git config sanity.tasksurl https://acunote.myco.com/tasks/<>

-o or --open: Open the URL for the task. local-open is supported. (The URL pattern needs to be configured in your git config - see "-l or --link")

Hooks

append-task-url

Type (rename to): prepare-commit-msg

Depends On: git-task

Appends the current bugtracker task number, or link if sanity.taskurl is specified in your git config (see git task), to the end of your commit messages.

append-task-description

Type (rename to): prepare-commit-msg

Depends On: git-task

Appends the current bugtracker task number and description to the end of your commit messages.


Caveat: You won't be able to just quit your editor to cancel a commit since the commit message won't be empty. Instead, you'll have to delete the appended task number/link and save the commit message file.

License

git-sanity is distributed under the BSD License

Something went wrong with that request. Please try again.