Saturday, February 20, 2016

Git for Team Projects

In this post, I'm gonna explain how to use Git for our personal projects and contribute to others projects most importantly team works.  We assume that every reader knows about Git before this post. Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.  Git is easy to learn and has a tiny footprint with lightning fast performance. It outclasses SCM tools like Subversion, CVS, Perforce, and ClearCase with features like cheap local branching, convenient staging areas, and multiple workflows.

For example, scenario lets look how we can contribute WSO2 code base and what are the steps behind the contribution.

Steps - Contribute to organization repo

Follow these instructions to contribute to the WSO2-Extensions code base. 
  1. Fork the required repository from  WSO2-Extensions  to your personal account. 
    This will get the copy of repository into our account. 

  2. Clone the code base to your local machine, and then change to the local directory where the code was cloned.
For example,
if the repository is Inidentity-outbound-auth-linkedIn:
git clone<OWNER>/identity-outbound-auth-linkedIn.git

  1. Set your working directory by doing one of the following:
    1. To work with code on a project that is under development, set your working directory to the appropriate branch using the checkout command as follows:
      git checkout <REMOTE_BRANCH>
    For example, to work with a branch named refactoring:
    git checkout refactoring
    1. To work with code in a project that was already released, set your working directory to the appropriate tag for that release using the checkout command as follows:
      git checkout tags/<TAG_NAME> -b <LOCAL_BRANCH>
      For example, to work with the v1.1.0 tag, which represents the 1.1.0 product release:
        git checkout tags/v1.1.0 -b v1.1.0
Tip: To help avoid confusion, set the local branch name to the same name as the remote branch.

  1. Build the product using Maven to validate whether the existing project contain any issues or errors before you do your changes in the repo.

  2. If you need to add a new file to the repository:
    1. Add the new file.
git add <FILE_NAME>
For example:
git add
    1. Commit the newly added file to your local repository.
git commit -m "<COMMIT_MESSAGE>"
For example:
git commit -m "Adding a new file"

  1. If you need to update an existing file in the repository:
    1. Open the file that you want to update and make the necessary changes.
    2. Commit the changes to your local repository.
git commit -m "<COMMIT_MESSAGE>" -a
For example:
git commit -m "Updated the clauses in the terms and conditions file" -a

  1. If you are working with a branch instead of a tag, sync the upstream repository with your local branch.
git fetch <REMOTE_NAME>
For example:
git remote add wso2_upstream
git fetch wso2_upstream
git merge wso2_upstream/refactoring

  1. Push the changes to your own Git repository. Before push better if we check is there any changes applied in the master branch so pull the changes from wso2 master branch before push the changes(to perform this pull we should set upstream url as mentioned in 8).
git pull
git push

  1. Send a Git pull request to the WSO2 Git repository.
Your pull request will be authorized after it has been reviewed by the team lead, release manager, or responsible person for the corresponding Git repository.