Git #101 tips and best practices

Git #101 tips and best practices

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

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

# update your code from main repo
git push
Checkout branches
# 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:
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 I’m sure the code is safe so I simply use “D”.

Delete remote branch:
git push origin :BRNACH_NAME
Delete several branches at once:
git branch | grep PATTERN | xargs git branch -D

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

Leave a Reply

Your email address will not be published. Required fields are marked *