Posts tagged with git
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.
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 Github.com 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 Heroku.com 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 @ https://github.com/bluescripts/github-postcommit-shinie and then cd into the project folder
$ git clone https://github.com/bluescripts/github-postcommit-shinies.git
$ 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
http://falling-moon-8152.herokuapp.com/ | firstname.lastname@example.org:falling-moon-8152.git
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 config.ru -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!
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!
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:
- git merge
it can be useful to do a:
- 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
- git checkout -b fancyfeature
# change some files, etc
- git commit -a -m "made some changes"
# more fixes, etc
- git commit -a -m "stupid fancyfeature. maybe this will work"
# push a copy to github so my colleagues can review my changes
- git push origin fancyfeature
# more changes
- git commit -a -m "woo, got the fancyfeature working"
# i'm done! switch back to master
- git checkout maste
# merge in all my changes, squash them into my working dir
- git merge --squash fancyfeature
# commit those changes as a single commit
- git commit -a -m "Added fancyfeature"
# tag the branch just in case we need it later
- git tag archive/fancyfeature fancyfeature
# delete the topic branch in my local repo
- git branch -D fancyfeature
# delete it on github too
- git push --tags origin :fancyfeature