Git
Git Best Practice
CLI Git Setup
-
Download latest version of Git and link to your Github account. If you do not yet have Git installed or it is not linked to your Github account follow the instructions here: https://help.github.com/en/github/getting-started-with-github/set-up-git to do so.
-
Make sure you have the correct Github permissions and have been added to any needed trinity-insight teams.
-
Navigate to the repo you want to work on, copy the "clone with HTTPS" URL to your clipboard and use command "git clone {URL here}" in the command line to clone the repo to your local computer.
-
Start coding!
Github Desktop Setup
-
Download latest version of Git and link to your Github account. If you do not yet have Git installed or it is not linked to your Github account follow the instructions here: https://help.github.com/en/github/getting-started-with-github/set-up-git to do so.
-
Make sure you have the correct Github permissions and have been added to any needed trinity-insight teams.
-
Install and setup Github Desktop app on your computer. Instructions for this can be found here: https://help.github.com/en/desktop/getting-started-with-github-desktop/installing-github-desktop
-
In the Github Desktop app, click on the repository dropdown in upper left corner => Add => clone repository, then navigate to the repo you want to work in and click clone.
-
Start coding!
When to Push and Pull
Pull
- Before making coding changes always pull in the updated repo. Do this by using command "git pull" in CLI, navigating to partner account repo and clicking pull origin at the top of the Github Desktop app, or by clicking on the push/pull icon to the right of desired repo in the source control tab of VS Code. If you just cloned the repo to your local computer it will already be updated and this step is not needed.
Push
-
When ready to push to Github use command "git push origin master" in CLI, click "commit to master" in Github Desktop app, or click on the push/pull icon to the right of desired repo in the source control tab in VS Code.
-
Make sure to be descriptive with the updates you made in your commit message.
-
Whenever a main task/non sub task is completed push to Github, ie. Launch test, test development, test QA. Also, always push changes to Github when you take lunch and when you pivot to a different task.
-
When you finish addressing any QA notes push to Github before notifying team member to verify notes have been met.
Git Branching
Branching Naming Conventions and Setup
-
When working on collaborative projects always create a feature branch and push changes there instead of master. Use CLI command "git branch" to see what branch you currently have selected, "git checkout {name of branch to be selected}" to navigate to desired branch, or "git branch {name of feature branch to be created}" to create a new branch. Using the Github Desktop app you can create a new branch by clicking on the 'Current Branch' tab in the top nav and then the 'New Branch' button in the resulting dropdown. In VS Code simply click on master to the right of your desired repo and follow the prompts from there.
-
The branch should always start with "feature" and should provide insight to what task you plan to accomplish with that branch, ie. feature-homepage-form-validation.
-
Once a feature is completed push all changes to Github, navigate to the Pull requests section in the repository on github.com and click on New pull request. Adjust base: {feature branch you want to merge into master} and compare: master, then create the pull request.
-
When reviewing a teammates pull request look at the code, do not accept without reviewing.
-
When accepting the pull request of a teammate always let the owner of the code make the final merge to master.
-
When making changes to a feature branch best practice for pulling as explained above still applies. Unless it is a newly created branch, when desired repository is selected in CLI use commands "git pull" and "git merge master". This will pull in the updated repo, and also pull in any changes from master into your feature branch, this will help avoid merging conflicts in later steps.
Resolving Merge conflicts
-
Go to vsCode and select the source control tab on the left hand side. You may also resolve the conflict with the Github GUI you will be redirected to based on your personal preference.
-
Select desired source control provider and then click the changes to see feature branch side by side with master branch with changes highlighted.
-
Resolve conflict by selecting option "accept incoming change" or the other option to retain what is already on master and abort specific change from feature branch.
-
Conflicts should always be addressed BEFORE requesting a teammate to review a pull request.
-
If master is a production branch make sure to verify changes on the live site after pull request is approved and you have merged changes to the production branch.