How to Use Git Like a Boss

cover
14 Jul 2024

When Should One Commit Code?

Every time you have a small feature working you should commit.

How to Commit Tour Code??

  1. There are two ways to commit your code:
  • When you start working on your feature branch, update your project with the latest changes with the command below:
git pull origin master 
  • As you work on your feature branch, keep updating your project with the command above. Once you are done, create a feature branch using the command below:
git checkout -b feature-branch 
  • Stage your changes, and push your code with the commands below:
git add . 
git commit -m "Describe your changes here" 
(optional to make sure is clean) git status 
git push origin feature-branch
  • Once you do this, create a pull request on the code repository you are using (Github or Gitlab) and merge your code
  1. Another way to work with git is by using the following steps:
  • When you start working on your feature branch, update your project with the latest changes with the command below:
git pull origin master 
  • Create a feature branch using the command below:
git checkout -b feature-branch 
  • Once you are done, save your changes using the commands below:
git add . 
git commit -m "Describe your changes here" 
  • Return to your master branch, and update it using the following commands:
git checkout master 
git pull origin master 
  • Return to your feature branch, and merge the master to your feature branch using the command below:
git checkout feature-branch
git merge master  
  • At this point, there might be conflicts to be resolved. After they are resolved, commit again and push your code
git add . 
git commit -m "Merge master"
git push origin feature-branch 
  • Once you do this, create a pull request on the code repository you are using (Github or Gitlab) and merge your code

Happy coding!