Intro to using git

From StatusNet

(Redirected from IntroToUsingGit)
Jump to: navigation, search

Contents

[edit] Setting up your environment

  1. Install Git on your workstation.
  2. In a Web browser: create an account on gitorious http://gitorious.org.
  3. Go to the StatusNet project page on gitorious [1]. Click on "mainline."
  4. Click on "Clone this repository on Gitorious." You will be prompted to enter a name for your clone.
  5. Locally, download the clone of StatusNet:
git clone git@gitorious.org:~<GITORIOUS-USERNAME>/statusnet/<YOUR-CLONE-NAME>.git

Add statusnet's mainline git to your local repository so you can stay up-to-date:

cd <YOUR-CLONE-NAME>
git remote add statusnet git://gitorious.org/statusnet/mainline.git
git fetch statusnet

Create a branch that tracks your (origin) branch of 0.9.x. Complete this action from within the repository directory:

git checkout -b 0.9.x statusnet/0.9.x

[edit] Let's get developing!

Think of a new feature or bug fix for 0.9.x:

cd <YOUR-CLONE-NAME>
git checkout 0.9.x
git branch <MY-NEW-FEATURE>
git checkout <MY-NEW-FEATURE>

Do some development.
Things to keep in mind: Keep the scope of the branch limited to a feature or bug fix, it makes merge requests easier to review.

Commit your changes:

git commit -a

You should "rebase" your "<MY-NEW-FEATURE>" branch before you submit your branch. This will first take out your changes, apply any upstream changes, then try to remerge your changes. This will allow you to solve any conflicts your patch may have.

git fetch statusnet
git rebase statusnet/0.9.x

[edit] While you're developing

Be sure to check for updates from the mainline of statusnet to your branch:
(Do this as often as you like to keep up to date)

git checkout 0.9.x # Making sure we're on the correct branch
git merge statusnet/0.9.x


[edit] Push your changes to gitorious

  • Upload your revised branch to Gitorious:
git push origin <MY-NEW-FEATURE>

[edit] Creating a merge request in Gitorious

Once you've committed your work branch and pushed it back into your personal clone in Gitorious, you can create a merge request which will alert the StatusNet core developers that your changes are ready, conveniently showing what's changed and giving a place for comments and further revisions.

  1. Go to the Gitorious Web site http://gitorious.org. Login and go to the clone you created in the first part of this tutorial.
  2. Click the "Request merge" button on the sidebar
  3. Fill out the fields...
    • Summary one-line description
    • "Description more detailed description; references to related bug reports or documentation are always great here -- make sure reviewers know the purpose of your patch and what it's trying to resolve
    • "Target repository in most cases this should be "mainline", unless you're coordinating with another developer's personal work clone
    • Target branch this is the easiest to get wrong! It defaults to "master" but in most cases you'll probably have been working against the current development branch such as "0.9.x". You must choose the same source branch you were originally working from, or the diffs won't display correctly and it'll be a lot harder to review the changes.
    • Source branch select the work branch on your personal clone that you're merging.
    • Select commits generally you'll select all changes from the branch point to your last change.
  4. When done, click "Create merge request".

A mail will be sent out to notify the core developers. Any comments on the request will alert you back via e-mail as well.


[edit] Tips

git branch -a # show all branches
git branch -D <MY-NEW-FEATURE> # delete branch, it's ok they're free!

If you want to keep our remote branch up-to-date (say more than one dev working on the same branch) then we can push them there for everone:

git fetch statusnet
git checkout 0.9.x # Making sure we're on the correct branch
git merge statusnet/0.9.x

git push origin HEAD
git diff # Shows changes between now and last commit
git reset --hard HEAD~ # undoes last commit 

[edit] git config

git config --global user.name "FirstName LastName"
git config --global user.email "user@example.com"
git config --global color.ui "auto"

[edit] Useful links

Personal tools