Git Tips

Quick, actionable tips to improve your Git workflow. Grouped by series for easier learning.

Git Noob Tips

4/22/2022

Deleting a local branch is rather easy:

4/29/2022

Git usually gets confused when you rename/move a file and change its content at the same time. Git would think the old file was deleted and a new file was created. All of the version history is simply lost.

5/6/2022

When pushing, your local branch must be ahead of the remote branch, otherwise, the push is rejected. This is called the "fast-forward rule". In the case of a feature branch, one can force-push, but one should never force-push to master.

Git Default Branch

Git Noob Tips

5/13/2022

Until some 2 years ago, the default branch of every git repository was called "master". It was a synonym for "the default branch". Then there was an initiative to change this because it was offensive to some people. GitHub was the first one to react and changed the default branch name to "main". On git, the default branch name stayed "master", but an option was added to change it.

Stash Message

Git Noob Tips

5/20/2022

Git stash is a place to store your unfinished work to do things like changing the branch or pulling the latest changes. Then one can pop the changes and continue working.

Auto-Stash

Git Noob Tips

5/27/2022

This one is a child of tips 3 and 4. First of all, if we want to rebase every time we pull, why not make it the default? Also, if we want to stash our uncommited changes every time we pull/rebase, why not make it automated? That's what this tip is about:

Push Default Branch

Git Noob Tips

6/3/2022

Let's say you created a new branch locally, named my-fantastic-branch, and you want to push it to the remote repo. The first time you're pushing, you need to specify the name again and instruct git that this is your "upstream" branch from now on so that git creates the branch on the remote repo: