Git
We use git to help us manage changes to our source code over time. Follow along to get some insights about our workflow.
If you are new to git, please read the following blogs to get started:
Setting up a new project
Setting up a remote repository
We use Bitbucket for web-based version control repository hosting service, so if not already done
- Create a new project in Bitbucket.
- Create a new repository in the newly created project.
- Create a new branch named
develop
. -
Navigate to
Settings -> Workflow -> Branch permissions
.(i) Create branch permission for branch
develop
andmaster
.(ii)Uncheck the
Allow rewriting branch history
andAllow deleting this branch
checkbox for both the branches.(iii) Onboard your team.
master
stable branch and should only be used for client and production releases.
develop
should always be the latest stable branch where all development PR's would be sent to.
Creating a PR template
PR template helps us to remind of some things which are essential for the project's sanity to be maintained. While working with the team we all must follow some basic rules and provide useful information to the reviewer.
If you are an admin of the repository
- Go to
Settings
. -
Under the
PULL REQUESTS
heading, clickDefault description
and paste the following content.## Description ### Why was this change necessary? [text here] ### How does it address the problem? [text here] ### Are there any side effects? [text here] ### Do you want any specific feedback? [text here] ### Do you have resources that will help the reviewer? [MP-](https://messengerpro.atlassian.net/browse/MP-) ### Zeplin screen design links? [link here]
-
Change the Jira tickets prefix according to your Jira project and click save.
- If you have already created your project locally then modify it's
.gitignore
file according to you and connect your local project to remote repository else clone the project to your local machine.
Connecting your web repository to the project management tool.
We use Jira as our project management tool.
Please contact your project manager to set up workflows which will help in automating issue/ticket tracking process.
Jira Linking
Generally, all of your tasks are mentioned in the project management tool. This helps in keeping a record of the productive time you spend working for the company.
Branch Naming
Git branches are effectively a pointer to a snapshot of your changes. When you want to add a new feature or fix a bug—no matter how big or how small—you spawn a new branch to encapsulate your changes. If you have not created a new branch till yet go ahead and create one.
Type the following command to create a new branch
git checkout -b {$new_branch _name}
Most of the time branched should be created by your issue/ticket number in Jira.
{$your_jira_project_prefix} {$dash} {$issue_number}
Here are a few examples of how the branch should be named.
Ideally, you should work with one ticket at a time, raise its PR to develop
and pick another one but if the issue is too small or it takes little time and effort to fix, you can pick multiple tickets at a time. Below are some sample branch names.
Working with a single ticket at a time
ALT-223
QQ-54
INFLCR-223
Working with multiple tickets at a time
ALT-223-ALT-224-ALT-305
QQ-54-QQ-125-QQ-87
INFLCR-223-INFLCR-25
However, if you happen to work on an issue which is not on Jira yet, convey this to your project manager to put that on Jira and in the meanwhile, you can create a branch like
- chores-AddErrorHandler
- fix-SplashAnimationFix
- feat-AddContinueButtonInWishlistScreen
If before raising your PR the ticket is created, rename your branch using
git branch -m {$new-name}
Commit message format
We follow a strict specific commit format so that every commit message is well-formatted and self-explanatory. It helps the reviewer or teammate to quickly understand the intention of the commit and provide feedback accordingly.
Below are some sample commit message, their structure, and explanation of them.
feat(ALT-653): Add continue button in the login screen to navigate to next page
fix(INL-345): Fix Splash screen animation bug
chores(*) : Add progaurd rules, base project set up
This commit message is divided into 4 sections:
<type>(<scope>): <subject>
<BLANK LINE>
<body>
Type | Description |
---|---|
feat() | This essentially represents that your commit will add a feature. |
fix() | This represents that your commit will fix a bug. |
chores() | This represents that your commit is doing some project structure related work. |
docs() | Documentation only changes. |
test() | Add missing tests. |
refactor() | A code change that neither fixes a bug or adds a feature. |
perf() | A code change that improves performance. |
-
Type
: These represent the type of feature or fix your commit will do. -
Scope
: This could be anything defining the place of change a commit. Usually, it can be the ticket number you are working on. If there is no ticket assigned you can replace it with an asterisk*
. -
Subject
: This is a short yet meaningful description of your commit. Below are few points to keep in mind for a descriptive commit message.- Capitalize the first letter.
- Limit the subject line to 50 characters.
- Do not end the subject line with a period(.).
- Use the imperative mood in the subject line. For example:
Fix Splash animation bug
notFixes Splash animation bug
norFixed Splash animation bug
.
-
Body
: Body in a commit message is used to describe changes in your commit in a more descriptive way. Although it is not always compulsory to writebody
in every commit message but it is a good practice to write it to explain your changes.
Here is how you can write a commit message body.
- Write
git commit
command without any flags. - It will open your pre-configured editor.
- If the editor is vim then enter insert mode by pressing
i
orinsert key
. - Enter your precise commit message in the first line.
- Leave a blank line.
- Enter the description body of your changes.
- Press
Esc
and then press:wq
to save and quit the editor.
Raising a PR
Few important things to remember while raising your PR to be merged so that we all can benefit from it and it's important to follow some standard conventions while creating pull requests:
Before creating a pull request
We follow the concept of rebase to maintain a linear project history of git tree and clean branching model, so it is important to squash your commits and rebase with develop branch.
Do not hesitate to push your work regularly to the cloud, but after completing your task combine your commits into minimum meaningful commits.
Note: Do not try to squash the commits of
develop
,master
or whichever branch on which multiple people are working on. Their commit history and integrity should be maintained.
Here are a few steps you can follow to achieve the same.
- Commit all your work.
- Count the number of commits you want to squash using
git log --oneline
. - Start an interactive rebase session by typing
git rebase -i HEAD~{$number_of_commits_to_squash}
in terminal. - In the window pick or squash the commits using
p
ors
after entering insert mode. - If the conflicts occur resolve them using git mergetool.
- After resolving the conflicts add them using
git add .
and continue rebasing them usinggit rebase --continue
.
Read the above-described process in detail here.
Pro-tip: You can also achieve the above same process using git reset HEAD~{$number_of_commits_to_squash}
. It avoids conflicts by simply un-committing your work and then you can simply combine your work in a single commit.
git pull --rebase origin develop
Rebase your branch from develop
- Checkout to develop branch.
- Update your local branch using
git pull origin develop
. - Checkout to your branch and run
git rebase develop
. - Resolve your conflicts if any using the above-described process.
- Force push your changes using
git push -f origin {$branch_name}
Follow and maintain below points in your PR for it to be reviewed
- Your PR should be small and specific to a unit or granular task.
- If you have implemented anything new, please mention the relevant links to it.
- The code contained within will meet the best practices set by the team wherever possible.
- Write your test cases vigorously.
- Fill the description form, add all your working teammates as reviewers so that every person is aware of changes in the code base and hit the
Create PR
button.
Reviewing a PR
Having proper communication on the internet for the benefit of the project is one of the most important aspects of the project. Following practices collected from Github's blog and other sources should be followed.
- Ask, don’t tell. (“What do you think about trying…?” rather than “Don’t do…”).
- If you disagree strongly, consider giving it a few minutes before responding; think before you react.
- Explain your reasons why code should be changed. (Not in line with the style guide? A personal preference?) Offer ways to simplify or improve code.
- Avoid using derogatory terms, like “stupid”, when referring to the work someone has produced.
- Be humble. (“I’m not sure, let’s try…”).
- Avoid hyperbole. (“NEVER do…”).
- Aim to develop professional skills, group knowledge, and product quality, through group critique.
- Be aware of negative bias with online communication. (If the content is neutral, we assume the tone is negative.) Can you use positive language as opposed to neutral?.
- Use emoji to clarify tone. Compare “:sparkles: :sparkles: Looks good :+1: :sparkles: :sparkles:” to “Looks good.”
Responding to feedback on Pull Requests
- Don't take it personally. The review is of the code, not you.
- Be grateful for the reviewer's suggestions. ("Good call. I'll make that change.")
- Try to respond to every comment.
- Consider leading with an expression of appreciation, especially when feedback has been mixed.
Best Practices
- Rebase is preferred to merge as it keeps the tree compact.
- Rebase your working branch before you start working and before you create a pull request.
- Always push your commits at the end of the day, so in case of emergency, other team members can pick up where you left.