Git useful commands

# Merge selective commit
If you have multiple branches in your repository and there are set of commits applied at one branch 
, e.g., Branch1
  • changes for web.config (commit no: ediekd3839929293)
  • changes for db (commit no: gdjsk29182kdlk)
Now you want to merge code change for db (gdjsk29182kdlk) in Branch2.
 
Then first goto Branch2
  • git checkout Branch2
Merge changes from commit no/hash that you want , e.g.,  
  • git cherry-pick gdjsk29182kdlk
# Create new branch like exisiting one
git checkout -b <branch name>
 
# To create empty branch
git branch --orphan <branchname>
 
# Undo unstaged changes
git reset --hard
Note: be cautious this it'll reset unstaged changes in the repository, so use this when you're really sure
 
# There are some cool features that you can leverage at Unix/Linux terminal by concatenating multiple commands 
&& Combine two commands to execute in single line , e.g.,
  • git reset --hard && git checkout -b newbranch1
 It'll first reset all unstaged changes and then create newbranch1 like current branch
 
GIT is fantastic tool, incase you've any query then reach out to me @sumitjolly (twitter)