This article includes instruction to configure git and provides guidelines for proper use of git branches.
If using VS Code, make it the default git editor:
git config --global core.editor "code --wait"
Make git remember credentials:
git config --global credential.helper cache
git config --global credential.helper "cache --timeout=2500000"
Make main
the default branch name:
git config --global init.defaultBranch main
Initialize git and specify branch name:
git init -b main
VS Code can provide a visual way to interact with git. But ensure you are familiar with the following git commands:
- git fetch
- git add -A
- git commit -m "implement feature-1"
Create a new branch and switch to it: git checkout -b <ticket-nnn_feature>
If needed, delete a local branch: git branch -d <obsolete-branch>
Before making a pull request, consider following these steps. It ensures a clean git history and facilitates team work.
Note: You may use the VS Code integrated terminal. Howevere, if it doesn't behave properly, use the system terminal instead.
- Ensure all changes are committed.
- Ensure that the local and remote repose are in sync.
- Rebase onto
origin/main
to keep up to date withorigin/main
:git rebase -i origin/main
- Resolve conflicts if any and be sure all tests pass. You may have to repeat the previous steps if new changes need to be made.
- Rebase the branch to clean up its history:
git rebase -i HEAD~<n>
- Pick the earliest commit and mark the rest as fixup.
- Force push the current branch:
git push --force-with-lease origin <feature-branch>
- Create a pull request (PR) on a branch page on GitHub.
- Assign someone to review it.
- Once reviewed and all concerns have been answered, click on merge.
- Decide on a template and use that for the merge message.
- If tests pass on the main branch, then delete the feature branch to keep the history linear.
- Update the local main branch on your machine with the remote one on GitHub.