Git offers many commands, but which ones are most commonly used in real-world projects? ๐ค As an essential tool for version control, Git helps track changes, collaborate with teams, and maintain code stability. Mastering key commands boosts productivity, reduces conflicts, and keeps the codebase clean. Letโs dive into these frequently used commands! ๐
Agenda
- 0. Receiving a Task, for example, task ID 123
- 1. Get the latest code from the develop branch
- 2. Work on the task directly on the develop branch
- 3. Prepare to create a Pull Request (PR)
- 4. Create a branch for your code changes
- 5. Retrieve your stashed code (saved earlier using git stash)
- 6. Create a commit and write a commit message
- 7. Push code to the remote repository (GitHub, GitLab, Bitbucket, etc.)
- Finally, create a PR/MR into the develop branch on the remote repository and request a lead review. Done! Hehe ๐
0. Receiving a Task, for example, task ID 123
- Later, when you see a branch created with the number 123, you can assume it's the
taskId. - For example, in my team, we develop on the
developbranch.
1. Get the latest code from the develop branch
git checkout develop # switch to the develop branch
git pull # lfetch the latest code
2. Work on the task directly on the develop branch
CODING CHANGES ๐
After finishing your code, review your changes carefully and slowly.
Review the coding conventions.
Check if all console logs are removed.
Verify if there are any redundant imports.
Check for eslint issues.
If thereโs complex logic, add comments.
If thereโs too much if/else logic, refactor it.
...
Review your code in VSCode for better readability. If you want to look cool, use git diff and check instead! ๐
Make it a habit to review your code thoroughly before handing it to your lead for review! ๐
3. Prepare to create a Pull Request (PR)
After finishing your code, itโs time to prepare a PR.
However, while you were working, someone else might have updated the develop branch.
NSo, you must fetch the latest code from the develop branch before applying your changes.
git add . # stage all changes
git stash # save all code changes to stash (temporary storage)
git pull # fetch the latest code
4. Create a branch for your code changes
git checkout -b feature/123-add-address-ui
5. Retrieve your stashed code (saved earlier using git stash)
git stash pop
OPTIONAL: Resolve conflicts if there are any. Remember to test again to ensure the code still works smoothly. ๐
6. Create a commit and write a commit message
git status # view the changed files
git add . # stage all changes
git commit -m "[123] Add address UI
- More details about your PR
- Keep it short and descriptive"
๐Note the yellow text:
- The first line is the title.
- The second line is empty (MANDATORY).
- From the third line onward, provide additional details about your Pull Request.
This convention helps automatically populate the title and description fields in GitHub, GitLab, Bitbucket, etc.
7. Push code to the remote repository (GitHub, GitLab, Bitbucket, etc.)
git push -u origin feature/123-address-ui
Finally, create a PR/MR into the develop branch on the remote repository and request a lead review. Done! Hehe ๐
๐NOTES
- Each project may have different branch naming conventions; follow your teamโs rules.
- The branch you work on also depends on the team; itโs not always
develop. Not everyonefollows the same process as mine; everyone has their ownstyle.- The process shared above is something Iโve applied during my career and found effective. Iโm sharing it here for your reference; feel free to adapt it if you find it helpful. ๐
WISH YOU ALL GOOD HEALTH AND SUCCESSFUL LEARNING! โค๏ธ