# git ship alias

I use [git](https://git-scm.com/) for version control in the development of my software projects. As it's frequently the case that I'm the sole developer of these projects, I've adopted a simple trunk-based-style branching strategy in which I make new commits to a `devel` branch until deeming these changes stable enough to merge into `master`. This allows me to edit commits in the development branch before "finalizing" them.

I found myself repeating the process of checking out the "production" branch, merging the development branch, and pushing—essentially "shipping" stable code—so I created a [git alias](https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases). Let's check it out!

## git aliases

**git** aliases allow you to specify alternative names for commands. For example, you can use an abbreviation for the `checkout` command:

```sh
git config --global alias.co checkout
git co
```

Another handy feature is the ability to create an alias to a separate executable; this is done by prefacing the command with `!` on the command-line using `git config`:

```sh
git config --global alias.ship '!git-ship'
```

Remember to include the single quotes as `!` is a special history expansion character in popular shells such as **bash** and **zsh**. Also, be sure this executable exists in your shell's [`PATH`](https://opensource.com/article/17/6/set-path-linux).

## git-ship

My alias points to a separate executable shell script that chains together multiple **git** commands:

```sh
#!/bin/sh

prod=${GIT_SHIP_PROD:-master}
dev=${GIT_SHIP_DEV:-devel}

git checkout $prod && git merge $dev && git push && git checkout $dev
```

These commands perform the following actions:

1. check out the production branch;
    
2. merge the development branch into production;
    
3. push the production branch to the default remote;
    
4. and check out the development branch to prepare for new commits.
    

The targeted branches can be changed using environment variables.

In the directory of a given project, I "finalize" development commits and "ship" them to the remote repository with:

```sh
git ship
```

And it couldn't be easier!
