Git Commands

To initialize the git repository:-

  • git init

To clone the git repo from any version control:-

  • git clone

To Stage the changes:-

  • git add for specific file
  • git add . to stage all files.

To discard the changes to a specific file: -

  • git checkout –

To discard the all the changes: -

  • git checkout – .

To Commit the changes:-

  • git commit -m “initial commit” // commit comments

To Take pull from branch:-

  • git pull origin

To Push the code:-

  • git push origin

To Add code on you git repo:-

  • git remote add origin

To set the global user name & email:-

  • git config --global user.name "Your Name"
  • git config --global user.email "Your Email"

To Create New Branch:-

  • git checkout -b “branch_name”

To Switch Branch:-

  • git checkout “branch_name”

To Check origin Branch:-

  • git branch -r

To Check remote Branch with local branches:-

  • git branch -a

To merge branch:-

  • Git merge // branch name of the branch you want to merge in our branch

Cherry Pick

  • It allows you to select and apply specific commits from one branch onto another branch.

  • It's often used to pick individual changes without merging entire branches

Switch to target branch:-

  • git checkout

Cheery pick the commit:-

  • git cherry-pick

Cheery pick the commit:-

  • git cherry-pick

In case of Conflicts:-

  • Resolve the conflicts mannually
  • git cherry-pick –continue

  • In case you want to abort(cancel) the cherry-pick

  • git cherry-pick –abort