Posts tagged with git

Conveniently transfer files and projects between computers using git and SCP

Next time you need to transfer a file between computers and are about to reach for a USB flash drive, think about the following two cases. If either of them matches, you have an alternative! As icing on the cake, you can use either method whether you are on a Linux, Mac, or Windows-based system.

Continue reading...

Adding labels and re-assigning Github issues via commit message

A very nice feature that Github added some time ago on Issues 2.0 is the ability to refer to and close issues when doing a "git commit" via commit message:

git commit -m 'just fixed issue #123'

That's nice, but what if we want to keep that issue open, change its state, or assign it to a different person in the team? As an example, what if I'm working on a bunch of issues, and I want QA to test them before they get closed?

Well, we have two ways of doing this:

1. Open your web browser of preference. Go to and sign in. Find the repository of the project you are working on. Find the issue you want to modify on the issues page of the project. Get amused by that very friendly user interface. Add/change the labels to the issue on the right panel. Assign someone to the issue using the "gears" drop box icon. Easy!



2. git commit -m 'updated issue #123 ~QA =steve'

If you are like me and would like to do option 2, keep reading! (If not, do option 1 a few hundred times and maybe we'll see you again soon! :P)


Luckily, Github user bluescripts wrote a very simple ruby app using the Sinatra web framework that can be easily hooked up into our project's repository using the Github Service Hook: Post-Receive-URL. This Sinatra app can be deployed and hosted on Heroku which gives you some free monthly Dynos enough for this purpose.

Here are the steps to get this app running on Heroku:

1. Go to and sign up for an account (free)
2. Download and Install the Heroku Toolbelt (Mac / Win)
3. After installing the Toolbelt you will have access to the "heroku" command from your command shell, type in:

$ heroku login

Enter your Heroku credentials (email/password) and upload your SSH public key.
If you have any trouble on this steps please refer to the Heroku quickstart guide.

4. git clone this project @ and then cd into the project folder

$ git clone
$ cd github-postcommit-shinies

5. install the heroku gem

$ gem install heroku

6. install the bundler gem

$ gem install bundler

7. run bundle install to setup your bundle locally

$ bundle install

8. add and commit the Gemfile.lock file

$ git add Gemfile.lock
$ git commit -m 'Gemfile lock'

9. create the app on the Cedar stack

$ heroku create --stack cedar

After running this command you will see something like this:

Creating falling-moon-8152... done, stack is cedar |
Git remote heroku added

Copy and save the deployment Heroku URL of your app, we will use it later. Also you can check this URL on Heroku/myapps.

10. deploy your code to Heroku

$ git push heroku master

11. check the status of your app

$ heroku ps

If everything goes fine you will see your app up and running.

Process State Command
------- --------- ------------------------------------
web.1 up for 1m bundle exec rackup -p $PORT

Now go to the Admin page of your Github repository and click on the Service Hooks button on the left menu then click on the Post-Service-URLs button and paste your Heroku URL of your app and click the Update Settings button. Done!


Git tip: show current branch and time elapsed since last commit in command line

If you use git and have ever run into the frustrating situation of working for 2 hours on the wrong branch, then adding this code snippet - courtesy of Wen-Tien Chang (Twitter: @ihower) - to your ~/.bash_profile is for you:

With this trick, the command line will show the branch name, plus the time elapsed since last time you checked in the code. It reminds you that you should check in the code often and in small steps, which is good.
Also, you can have you "git checkout branch-name" to have sweet auto-completion for branch name by press "tab". Thanks, Wen-Tien Chang!

Creating and deleting topic branches with git and github

Topic branches are a useful convention when working with git, the version control system. A topic branch lets you work on a new feature or a bugfix in isolation from the master branch. It’s particularly useful when working on several bug-fixes or features simultaneously.

The branches are typically named after the new feature, e.g. “fancyfeature” and are short-lived. Once you’ve completed work, you can merge them back into master. Instead of using a standard:

  1. git merge

it can be useful to do a:

  1. git merge --squash

This allows you to squash all the commits on the topic branch (which may have included various dead ends, repeated tweaks) into a single commit on master.
This is the strategy shown below:

# make a new topic

  1. git checkout -b fancyfeature

# change some files, etc

  1. git commit -a -m "made some changes"

# more fixes, etc

  1. git commit -a -m "stupid fancyfeature. maybe this will work"

# push a copy to github so my colleagues can review my changes

  1. git push origin fancyfeature

# more changes

  1. git commit -a -m "woo, got the fancyfeature working"

# i'm done! switch back to master

  1. git checkout maste

# merge in all my changes, squash them into my working dir

  1. git merge --squash fancyfeature

# commit those changes as a single commit

  1. git commit -a -m "Added fancyfeature"

# tag the branch just in case we need it later

  1. git tag archive/fancyfeature fancyfeature

# delete the topic branch in my local repo

  1. git branch -D fancyfeature

# delete it on github too

  1. git push --tags origin :fancyfeature