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.
-
This will get the copy of repository into our account.
- Clone the code base to your local machine, and then change to the local directory where the code was cloned.
git clone <EXTENSION_REPOSITORY_URL>
For example,
For example,
if the repository is Inidentity-outbound-auth-linkedIn:
git clone https://github.com/<OWNER>/identity-outbound-auth-linkedIn.git
git clone https://github.com/<OWNER>/identity-outbound-auth-linkedIn.git
- Set your working directory by doing one of the following:
- 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
git checkout refactoring
- 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.
- Build the product using Maven to validate whether the existing project contain any issues or errors before you do your changes in the repo.
- If you need to add a new file to the repository:
- Add the new file.
git add <FILE_NAME>
For example:
git add mycode.java
- Commit the newly added file to your local repository.
git commit -m "<COMMIT_MESSAGE>"
For example:
git commit -m "Adding a new file"
- If you need to update an existing file in the repository:
- Open the file that you want to update and make the necessary changes.
- 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
- If you are working with a branch instead of a tag, sync the upstream repository with your local branch.
git remote add <REMOTE_NAME> <UPSTREAM_GIT_REPO_URL>
git fetch <REMOTE_NAME>
git merge <REMOTE_NAME/BRANCH_NAME>
For example:
git remote add wso2_upstream https://github.com/wso2-extensions/identity-outbound-auth-linked.git
For example:
git remote add wso2_upstream https://github.com/wso2-extensions/identity-outbound-auth-linked.git
git fetch wso2_upstream
git merge wso2_upstream/refactoring
- 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
git push
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.
No comments:
Post a Comment