Version 11, last updated by Vitalie Lazu at May 02, 2011 04:56 UTC

Read on Source/Git instructions tab how to install git for your OS and clone repository. Be sure to set git config with your name and email that is registered with your Assembla account.

Install Git

Install packages on debian/ubuntu:

$ sudo apt-get install git-core gitk git-gui

On openSUSE, package git-gui does not exist, but git-gui functionality is installed with package git.

Windows installer http://code.google.com/p/msysgit/downloads/list

MacOS

$ sudo port install git-core

or read this article

gitk - history viewer, can create tags/branches, checkout branches, reset branches, create patches, show diffs for commits

git-gui - tool for most common operations: commit and push, show you the diff of local changes

To push to git, you will need a ssh public and private key, generate them with below command, you can use empty passphrase:

$ ssh-keygen -t rsa

On windows you can use cygwin to generate ssh keys or generate on unix box and copy them to home folder: $HOME/.ssh/

Add the public key, generally found at ~/.ssh/id_rsa.pub, to your profile
Git for subversion users

Basic workflow

(if you are allowed to commit to master branch)

Run once to create your local work branch 

git checkout -b work 

Then make changes and commit to local branch.

Commit good practices:

  • If you commit with git-gui, please inspect diff of every file included in the commit. You should not modify or delete any files that are not part of logic changes related to a ticket. If you found some bugs, code to improve, write notes on a paper, fix a bug or implement a feature, make commit and then come back to notes and make separate commit with other changes. Each commit should contain only changes that are logically related.
    If you do not have a gui program to commit, inspect diff from command line: git-status - check files that need to be added/removed and git-diff to inspect changed files.
  • Enter a good description for commit: first line should be a summary up to 80 chars, then an empty line after, other lines can contain more descriptive message, if commit is related to a ticket use re #ticket_number to automatically add a comment to the ticket with commit description.

 

To push to repository:

rake git:push

this command will update code from remote repository and will rebase your work branch with master, merge master branch  and it will push your changes to remote server.

To update the code from central repository

rake git:update

A few Don'ts

Developers should not:

  • mix changes of breakout code base and vendor, extensions. Make 2 commits, one with changes to breakout, another to gem, plugin, extension, other vendor code. Breakout code base is ruby code from app and lib folders.

  • push merge commits to master or maint branches, only technical leaders can merge branches to master/maint. Ask them if you need your feature integrated in upstream. Feel free to merge master branch to your feature branch to keep your changes up to date.

Useful commands

  • You want to copy one commit from other branch to current branch
    git checkout current_branch
    git cherry-pick sha_id_from_other_branch
    Using gitk:
    1. right click on current branch and click check out this branch from popup menu
    2. click on commit from other branch, right-click and select Cherry-pick this commit
  • You forget to add some files to previous commit:
    git reset --soft HEAD^
    # add files that you have previously forgotten to add
    git commit -c ORIG_HEAD
    Using git-gui:
    1. Click Amend radio button above text area for commit description
    2. Add/remove files from commit
    3. Commit new changes