Many of you might have been using GIT for your personal projects or large team based projects. We at Rokomari heavily depend on GIT. For better outcome on collaborating projects, we follow a specific method with git. I am going to share this here.
First of all we need to arrange repository in a specific way before starting to code.
You will work with a company named ‘Company’ and they keep all the repository to Github. You are assigned to a new project ‘Syndicate’. The repository is created by the admin user of ‘Company’.
Repository URL: https://github.com/company/syndicate
Your personal GITHUB user is ‘AZLAN’ and you have read access to the repository.
To start working with the project you need to do the following:
- Clone the project to your workstation:
git clone https://github.com/company/syndicate.git
- Fork the project to your account. It will ask to choose the user or account where the fork will be created, choose your personal account.
A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project.
- As soon as your fork created, It will be created in your account if you have selected your own user. Normally the forked repository URL will be as follows: https://github.com/azlan/syndicate.git, copy that git url wither ssh or https.
- In your workstation, go to the project directory which is already cloned.
- Check how many repository remote destination is added:
git remote -v
Normally you will see two lines with same git repo, one for fetch and other for push.
- Now you need to add remote of forked project:
git remote add azlan https://github.com/azlan/syndicate.git
- Now again check the remotes:
git remote -v
It should show two remote in 4 lines with paired of push and fetch. Among them, two should be with azlan
Now you can start working. The steps below is repetitive every time you need to work with new issue with new branch.
- Make sure you are in master branch:
git checkout master
- Perform a pull request from origin master:
git pull origin master
- Perform a push to your fork to keep your master updated with latest code:
git push azlan master
- Create a feature branch:
git checkout -b '<NAME_YOUR_BRANCH>'
- Do your changes. perform:
git add .
git commit -am "<COMMIT_MESSAGE>"
- Push the branch to your fork:
git push azlan syndicate
- Work as much as you want, commit and push with step 5 and 6.
- Finally make a PR from github.com. If you go to the repository, You will see a message to create pull request.