How to Use Git Like a Boss

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.


This content originally appeared on HackerNoon and was authored by Caio Teixeira

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!

\


This content originally appeared on HackerNoon and was authored by Caio Teixeira


Print Share Comment Cite Upload Translate Updates
APA

Caio Teixeira | Sciencx (2024-07-14T12:00:12+00:00) How to Use Git Like a Boss. Retrieved from https://www.scien.cx/2024/07/14/how-to-use-git-like-a-boss/

MLA
" » How to Use Git Like a Boss." Caio Teixeira | Sciencx - Sunday July 14, 2024, https://www.scien.cx/2024/07/14/how-to-use-git-like-a-boss/
HARVARD
Caio Teixeira | Sciencx Sunday July 14, 2024 » How to Use Git Like a Boss., viewed ,<https://www.scien.cx/2024/07/14/how-to-use-git-like-a-boss/>
VANCOUVER
Caio Teixeira | Sciencx - » How to Use Git Like a Boss. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/14/how-to-use-git-like-a-boss/
CHICAGO
" » How to Use Git Like a Boss." Caio Teixeira | Sciencx - Accessed . https://www.scien.cx/2024/07/14/how-to-use-git-like-a-boss/
IEEE
" » How to Use Git Like a Boss." Caio Teixeira | Sciencx [Online]. Available: https://www.scien.cx/2024/07/14/how-to-use-git-like-a-boss/. [Accessed: ]
rf:citation
» How to Use Git Like a Boss | Caio Teixeira | Sciencx | https://www.scien.cx/2024/07/14/how-to-use-git-like-a-boss/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.