Useful git commands

Useful git commands

For every developer, git is a must-use tool for daily work. May it be work or side projects, one must know how to work with git.

Let's look at some commands that are essential for you.

  1. init - used to initialize a git repo on your local machine
git init
  1. clone - clones a remote repo to your local machine
git clone <repo-url.git>
  1. pull - fetch latest changes from the current remote repo to your local
git pull origin <branch-name>
  1. push - moves your local changes to the remote repo
git push origin <branch-name>
  1. checkout - switch to a new branch
git checkout <branch-name>
  1. checkout -b - creates a branch if unavailable and then switches
git checkout -b <branch-name>
  1. branch - lists all branches
git branch
  1. branch name - creates a new branch
git branch <branch-name>
  1. branch -d - deletes a branch
git branch -d <branch-name>
  1. add - moves your changes to the staging area
git add <filename1, filename2>
or
git add . 
(to add all files)
  1. commit - commits your changes and creates a commit history
git commit -m "commit message"
  1. branch -M - renames branch
git branch -M <new-name>

These are the basic commands that you will b using in your day-to-day work. There are some advance commands that you move to when you get yourself familiar with the above commands. Few commands are as follows -

  • git rebase

  • git cherry-pick

  • git log>file

and many more...

That's it for this one. Hope you learned something. Thanks for reading.

Follow for more.

My twitter