Git Commands Worth Remembering
19 Jan 2021 - Dan Petrow
Today I used Git again. I made quite a few mistakes already with git that caused my remote branches and my local branches to be in a bad state. Luckily, I created remote and local staging branches and managed to keep in tact.
What I learned tonight is the importance of deleting local branches when you are done with them because they cause problems if you leave them and don’t know exactly what you are doing. Here are some commands to remember.
- git checkout -b "branch" - This creates a new local branch.
- git push origin "branch" - This creates a new remote branch.
- git pull origin "branch" - This will take remote "branch" and make your local working branch look like remote "branch"
- git push origin --delete "branch" - This will delete a remote branch.
- git branch -D "branch" - This will delete a local branch.
- git branch - This lists our local branches and highlights our current branch.
- git branch -a - This lists all of our branches
- git branch status - This lists what branch we are on as well as any changes to commit.
- git reset --hard - discard local changes and restore yourself back to the last commit. </ul> Also keep a staging branch both locally and remotely that you only touch when you are sure that your commits won't break anything.