Git #101 tips and best practices

Tue Feb 27 2018

Git is an amazing tool, and I can surely say it saved my life for several times during my career.

adding code {#addingcode}
#create a new commit
git commit -am "some commit msg"
Updating code {#updatingcode}
# push your code to main repo
git push

# update your code from main repo
git push
Checkout branches {#checkoutbranches}
# checkout to the previous branch
git checkout -

#checkout to specific branch
git checkout BRANCH_NAME

#checkout to a NEW branch
git checkout -b BRANCH_NAME
Delete local branch: {#deletelocalbranch}
git branch -D BRANCH_NAME
#OR
git branch -d BRANCH_NAME

The difference is d will need the branch to be merged, and sometimes it bugs you if you squash the merge or whatever, so when Im deleting a branch Im sure the code is safe so I simply use D.

Delete remote branch: {#deleteremotebranch}
git push origin :BRNACH_NAME
Delete several branches at once: {#deleteseveralbranchesatonce}
git branch | grep PATTERN | xargs git branch -D

PATTERN is simply how to filter the branches you want to delete