Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

GitHub and Git

Anuruddha edited this page Mar 23, 2015 · 1 revision

Introduction

This page describes how we use Git & Github. It is aimed at individuals and organisations who may wish to get/use the source code, or contribute back to the source code through the collaboration model.

We use Github & Git as we want:

  • To simplify the way individuals and organisations can get access to the source code of our software.
  • Allow individuals and organisations to independently make changes and extend the software for their own needs
  • Allow individuals and organisations to easily contribute back any work they do through the Fork & Pull model.

Developers should follow the instructions below to make the above possible.

Useful links

  1. Pro Git book - http://git-scm.com/book/
  2. Git workflows book - http://documentup.com/skwp/git-workflows-book
  3. Git quick reference - http://gitref.org
  4. ThinkUp develop from source .

Install Git on your local machine & First time setup

There are a few places which contain good instructions on how to do this:

  1. set-up-git
  2. Git pro book online http://git-scm.com/book/en/Getting-Started-Installing-Git
  3. Git pro book for what to do for first time setup: http://git-scm.com/book/en/Getting-Started-First-Time-Git-Setup

Of note is:

$ git config --global user.name "John Doe"

$ git config --global user.email johndoe@example.com

and git config --list to check your git configuration.

When on windows, make sure to check that the following is set: core.autocrlf=true

We do this when using git on windows as all the files in the respository should have LF line endings. With core.autocrlf=true, all LF line endings are converted to CRLF line endings on checkout to a Windows machine. All files are converted back to LF line endings on commit from a Windows PC.

Fork the project on your personal or organisation github account.

If you dont have a github account already then you need to sign up and create one on on github.com (free accounts are fine).

Once you have a github account, the next step is to fork https://github.com/wso2/product-af.

see https://help.github.com/articles/fork-a-repo for help on forking in github.

Clone the repository to your local machine.

Create a directory in which you want the cloned project to exist within: e.g. in directory c:/dev/githubrepos/

git clone [fork repository url]

For example: git@github.com:USERNAME/product-af.git

see https://help.github.com/articles/fork-a-repo for help on forking in github

see https://help.github.com/articles/which-remote-url-should-i-use

After the clone operation has completed (should take a while), you should have a directory structure like the following:

Configure remotes

When a repository is cloned, it has a default remote called origin that points to your fork on GitHub, not the original repository it was forked from. To keep track of the original repository, you should add another remote named upstream:

The easiest way is to use the https url:

git remote add upstream https://github.com/wso2/product-af.git

or if you have ssh set up you can use that url instead:

git remote add upstream git@github.com:owso2/product-af.git

Master and Develop branches

By default when using git you will always have a branch named 'master'. On mifos we use another branch for any current development which we want to put in the next release. It is called 'develop'. You should checkout this branch also.

  • master: represents the latest stable release of wso2 appfactory.
  • develop: represents the bleeding edge development changes planned for next release of apfactory.

Create a topic branch for each unique piece of work

Its probably easiest if you create a new 'topic' branch on your forked repository for each unique piece of work rather than commit changes directly into master or our special develop branch. Why?

It means you can work on something very specific, get it up to date and send a 'pull request', To move on to a seperate piece of work, you simply create a different branch. It might also make it easier to keep up to date with the wso2/product-af repository as explained in next section.

Pull in upstream changes & Keeping your forked repository up to date.

There will be development changes to the wso2/product-af almost every day for the foreseeable future so its important to keep your fork of the software up to date with the latest changes.

To pull in upstream changes from repository you forked:

git checkout develop ... to make sure you are on the develop branch

git fetch upstream ...fetches changes from upstream respository but does not merge/rebase them

git merge upstream/develop ... merge in the new changes from upstream/develop repository into your repositories develop branch (You should not have any local changes on your master branch, if you do, use rebase)

git push origin develop ... push up the just merged changes to the develop branch on your fork

git checkout my-topic-branch ... switch to the topic branch you are using for piece of development work

git rebase develop ... rebase your topic branch which means, take in all latest changes and replay your work in topic branch on top of this - this produces cleaner versions/history

Note: the use of rebase for pulling in changes on top of your possible local dev changes as opposed to merge.

git push origin [branchname] ... do this if you are ready to push up your topic branch to your github account.

Read more about this at http://help.github.com/fork-a-repo/

Push local changes to forked repository

git push origin [branchname] e.g. git push origin master

Contributing back changes to original repository/authors

We would expect people to use the Fork & Pull model for collaborating back. Simply this means that we expect you to use Githubs tools here and to send pull-requests to us when you have a piece of work you want to contribute back.

Read more here: https://help.github.com/articles/using-pull-requests

Optional: If possible, it would nice if you could have your work in one commit rather than several broken up commits. If you followed advice on using a 'topic-branch' for you work and you have used rebase to get your changes up to date with the latest, and its only you doing work, you should be able to squash your changes over several commits into one commit as follows:

git rebase -i HEAD~2 ... squash last two commits i did on this branch into one.

or you can also reset your latest commits and re-commit as one as follows:

git reset --soft HEAD~2 && git commit ... soft resets last two commits and commits them back (asks for new commit message)

If one of the squashed commits have already been pushed to your remote repository, you need to do a git push origin remotebranchname --force.

Browsing Code in GitHub

For highlighting all usages and click a variable or object to search for other instances in the same project, use CodeNav.

To see IDE-like file browser tree, use Octotree plugin.