paint-brush
How to Use Git Like a Bossby@caiotbastone
300 reads
300 reads

How to Use Git Like a Boss

by Caio TeixeiraJuly 14th, 2024
Read on Terminal Reader
tldt arrow

Too Long; Didn't Read

Committing refers to staging the changes you make on your local machine, and then putting them on remote so your teammates and you can stay up to date with the changes of a project. Every time you have a small feature working you should commit. There are two ways to commit your code.
featured image - How to Use Git Like a Boss
Caio Teixeira HackerNoon profile picture

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!