Legit: An Alternative Git Workflow

By Jimmy Bonney | October 12, 2013

Legit

I am using GIT on a daily basis and I already shared some configuration options in a previous article. This article will shortly present a new tool – Legit from Kenneth Reitz – that provides some helpful additional git commands that can simplify your git workflow.

Install Legit

Pre-requisite

If python-pip is not installed on your system, the first step is to install it:

1
sudo apt-get install python-pip

In the following sections, I will shortly describe how to install Legit for the current user only, or system wide (as described in the original documentation).

Current User Installation

If you would like to install Legit only for the current user, you can run the following command to install it in your home folder:

1
pip install --user legit

By default, the binary files will be located under $HOME/.local/bin and it might therefore need to be added to the $PATH if this is not already there. To do so, simply edit ~/.bashrc and add:

1
2
# Add pip (python) local user bin folder
PATH=$PATH:$HOME/.local/bin

Finally, reload the file (this will allow you not to have to log out and log in again):

1
source ~/.bashrc

From now on, the legit command should be available in your console.

System-wide Installation

To make a system wide installation, a sudo pip install legit should suffice.

Add Legit Commands to CLI

To install the Legit shortcuts, simply run:

1
legit install

This will populate your ~/.gitconfig file with the necessary shortcuts.

Legit Homepage

Use Legit Shortcuts

Once everything is installed, it is just a matter of following the documentation.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$ git sync [<branch>]
# Synchronizes current branch. Stash, Fetch, Auto-Merge/Rebase, Push, and Unstash.

$ git switch <branch>
# Switches to branch. Stashes and restores unstaged changes.

$ git publish <branch>
# Publishes branch to remote server.

$ git unpublish <branch>
# Removes branch from remote server.

$ git prout <branch> <new-branch>
Creates a new branch off of the specified branch. Switches to it immediately.

$ git harvest [<branch>] <into-branch>
Auto-Merge/Rebase of specified branch changes into the second branch.

$ git graft <branch> <into-branch>
Auto-Merge/Rebase of specified branch into the second branch. Immediately removes specified branch.

$ git branches
# Nice & pretty list of branches + publication status.

Legit Settings

Note that if you use a terminal with a dark background, it might be necessary to update your settings so that you can read the output of all the new commands. To do so, just run:

1
legit settings

And update the value allow_black_foreground to False.

Final Word

Legit might not fit entirely in your workflow but some of the commands are actually just shortcuts of commands that you probably run in sequence on a regular basis. This should therefore simplify some of the operations that you conduct… at least, it does for me.



For the time being, comments are managed by Disqus, a third-party library. I will eventually replace it with another solution, but the timeline is unclear. Considering the amount of data being loaded, if you would like to view comments or post a comment, click on the button below. For more information about why you see this button, take a look at the following article.