• Stars
    star
    145
  • Rank 252,615 (Top 6 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 11 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Git utility scripts

Git utilities

This repo contains some Git utility scripts. The highlights are git open, git pull-request, git push-branch, and git undo, which you’ll never understand how you did without.

git-utils used to be pure Bash scripts, but they are now available as a Ruby gem:

gem install git-utils

See below for more details on the commands defined by git-utils. To learn more about how to use Git itself, see the tutorial book and online course Learn Enough Git to Be Dangerous.

Commands

  • git amend: alias for git commit --amend
  • git bump: makes a commit with the message "Bump version number"
  • git cleanup: deletes every branch already merged into current branch (apart from master, main, staging, development, and any branches listed in ~/.git-cleanup-preserved). Pass the -r option to delete remote merged branches.
  • git merge-into-branch [branch]: merges current branch into given branch (defaults to repo's default branch)
  • git minor: makes a commit with the message "Make minor changes"
  • git open: opens the remote page for the repo (macOS & Linux)
  • git polish: makes a commit with the message "Polish"
  • git pull-request: pushes the branch and opens the remote page for issuing a new a pull request (macOS-only)
  • git push-branch: pushes the current branch up to origin
  • git delete-remote-branch <branch>: deletes the remote branch if it is safe to do so
  • git switch <pattern>: switches to the first branch matching the given pattern
  • git sync [branch]: syncs the given branch with the remote branch (defaults to repo's default branch)
  • git sync-fork: syncs the default branch of a fork with the original upstream default (assumes upstream configuration as in “Configuring a remote for a fork”)
  • git typo: makes a commit with the message "Fix typo"
  • git undo: undoes the last commit
  • git graph: displays full repository history in graphical format; alias for git log --graph --oneline --decorate --all --full-history --author-date-order --no-notes

Aliases

Here are some suggested aliases:

git config --global alias.mib merge-into-branch
git config --global alias.pr  pull-request
git config --global alias.pb  push-branch

Further details

Some of these commands deserve further explanation.

git merge-into-branch

git merge-into-branch [target] merges the current branch into the target branch (defaults to repo's default branch). On a branch called add-markdown-support in a repo with default branch main, git merge-into-branch is equivalent to the following:

$ git checkout main
$ git merge --no-ff --log add-markdown-support

Note that this effectively changes the default merge behavior from fast-forward to no-fast-forward, which makes it possible to use git log to see which of the commit objects together have implemented a feature on a particular branch. As noted in A successful Git branching model:

The --no-ff flag causes the merge to always create a new commit object, even if the merge could be performed with a fast-forward. This avoids losing information about the historical existence of a feature branch and groups together all commits that together added the feature… Yes, it will create a few more (empty) commit objects, but the gain is much bigger than that cost.

In addition, the --log option puts the commit messages from the individual commits in the merge message, which is especially useful for viewing the full diff represented by the commit.

These options can be overriden (and thus restored to their defaults) by passing the options -ff or --no-log. git merge-into-branch accepts any options valid for git merge.

git push-branch

git push-branch creates a remote branch at origin with the name of the current branch:

$ git push-branch
* [new branch]      add-markdown-support -> add-markdown-support

git push-branch accepts any options valid for git push.

git sync

git sync [branch] syncs the given local branch with the remote branch (defaults to repo's default branch). On a branch called add-markdown-support in a repo with default branch master, git sync is equivalent to the following:

$ git checkout master
$ git pull
$ git checkout add-markdown-support

The main purpose of git sync is to prepare the current branch for merging with the default branch:

$ git sync
$ git merge master    # or `main`, etc.

(This is essentially equivalent to

$ git fetch
$ git merge origin/master

but I don’t like having master and origin/master be different since that means you have to remember to run git pull on master some time down the line.)

Installation

gem install git-utils

More Repositories

1

rails_tutorial_sublime_text

Sublime Text 2 setup used in the Ruby on Rails Tutorial
Python
718
star
2

sample_app_3rd_edition

The sample app for the 3rd edition of the Ruby on Rails Tutorial
Ruby
231
star
3

rails_tutorial_4th_edition_gemfiles

Gemfiles for the 4th edition of the Ruby on Rails Tutorial
Ruby
139
star
4

sample_app_rails_3_2

Ruby on Rails Tutorial sample application
Ruby
137
star
5

find_mass_assignment

Find likely mass assignment vulnerabilities
Ruby
115
star
6

action_cable_chat_app

The chat app for Learn Enough Action Cable to Be Dangerous
Ruby
62
star
7

rails_tutorial_snippets

Sublime Text 2 snippets used in the Ruby on Rails Tutorial
61
star
8

rails_tutorial_3rd_edition_gemfiles

The Gemfiles for the three example applications of the Ruby on Rails Tutorial (3rd Ed.)
Ruby
45
star
9

rails_tutorial_translation_2nd_ed

HTML source for the Ruby on Rails Tutorial, 2nd Edition, intended for translation
CSS
44
star
10

rails_tutorial_translation

Translations of the Ruby on Rails Tutorial book
Ruby
37
star
11

sample_app_4_0_upgrade

The upgraded sample app from the Ruby on Rails Tutorial
Ruby
27
star
12

pivotal-github

Ruby
25
star
13

rails_tutorial_translation_4_0_version

HTML source for the Rails 4.0 version of the Ruby on Rails Tutorial
CSS
23
star
14

ruby_tutorial

Files for Learn Enough Ruby to Be Dangerous
Ruby
14
star
15

js_tutorial

Learn Enough JavaScript to Be Dangerous tutorial directory
JavaScript
13
star
16

catch_cookie_exception

Catch and handle the CGI::Session::CookieStore::TamperedWithCookie exception that comes from changing the Rails secret string. See http://blog.insoshi.com/2008/08/15/a-security-issue-with-rails-secret-session-keys/
10
star
17

palindrome_app

A palindrome detector Sinatra App
Ruby
7
star
18

vim-files

Files for my (g)vim configuration
Vim Script
4
star
19

bullish_case_for_bitcoin

Light copyedit for "The Bullish Case for Bitcoin"
4
star
20

hello_app_heroku

Ruby
3
star
21

toy_app

A toy demo app for the Ruby on Rails Tutorial
Ruby
3
star
22

hello_app_original

A "hello, world" app for the Ruby on Rails Tutorial
Ruby
3
star
23

mhartl-palindrome

A sample NPM module for Learn Enough JavaScript to Be Dangerous
JavaScript
3
star
24

mhartl-archive.github.io

A sample website for Learn Enough CSS & Layout to Be Dangerous
CSS
3
star
25

js_tutorial_video

Learn Enough JavaScript to Be Dangerous tutorial directory
JavaScript
3
star
26

ruby-libraries

This is the repo for the talk Ruby Libraries Important for Rails from RailsConf 2013.
Ruby
3
star
27

another_test

3
star
28

mhartl_palindrome

Learn Enough Ruby palindrome detector
Ruby
2
star
29

enumerable

Repo for Enumerable talk
Ruby
2
star
30

le_custom_domains

HTML
2
star
31

python_package_tutorial

A sample package for Learn Enough Python to Be Dangerous by Michael Hartl
Python
2
star
32

example

Example site
HTML
1
star
33

book_name

1
star
34

yo

1
star
35

website_previous

A sample website for Learn Enough Git to Be Dangerous
HTML
1
star
36

mhartl_video_palindrome

Ruby
1
star
37

padrino_book

Working example of the Padrino book
TeX
1
star
38

demo_app

Ruby
1
star
39

first_app

The first app for the Ruby on Rails Tutorial
Ruby
1
star
40

foobaz_inclusion

Demonstrates file inclusion
TeX
1
star
41

barfing-rainbow

Illustrate a softcover thing
TeX
1
star
42

mhartl-palindrome-gem

Palindrome detector for Learn Enough Rub
Ruby
1
star
43

hungarian_book_template

A Softcover book template for Hungarian
TeX
1
star
44

failing_app_rails_4_0_rc1

A minimal failing app for Rails 4.0 RC1
Ruby
1
star
45

issues_test

1
star
46

foobaz

TeX
1
star
47

latex_sublime_text

Sublime Text snippets for LaTeX
1
star
48

foobar

Template PolyTeX book for Softcover
TeX
1
star
49

rails_tutorial_sample_app_7th_ed

1
star
50

book_template

Book template for long-form documents (including those for my math learning project)
TeX
1
star