Git Tips

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

Git Noob Tips

Delete Remote Branch
4/14/2026

Deleting a local branch is rather easy:

Rename or Move a File
4/14/2026

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.

Rebase When Pulling Master
4/14/2026

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 Default Branch

Git Noob Tips

4/14/2026

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

Stash Message

Git Noob Tips

4/14/2026

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

Auto-Stash

Git Noob Tips

4/14/2026

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

Push Default Branch

Git Noob Tips

4/14/2026

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:

Git Pro Tips

Empty Commit Message
4/15/2026

Avoid accidental empty commit messages by upgrading Git and relying on the editor prompt.

Force With Lease Alias
4/15/2026

Create a short alias for `push --force-with-lease` so the safer option is easier to use.

Change Last Commit Author
4/15/2026

Amend the latest commit with a different author name and email.

Delete Local Branches in Bulk
4/15/2026

Remove all local branches except the main one with a single pipeline command.

Enable Fetch Prune

Enable Fetch Prune

Git Pro Tips

4/15/2026

Automatically remove local references to remote branches that were deleted upstream.

Prune Remote Tracking Branches
4/15/2026

Clean up stale remote-tracking branches after they disappear from the remote.

Squash Last Commits
4/15/2026

Use interactive rebase to squash your recent commits into one cleaner commit.

Reword a Commit Message
4/15/2026

Change the message of an older commit with interactive rebase and the `reword` action.

Drop a Commit

Drop a Commit

Git Pro Tips

4/15/2026

Remove a commit from history with interactive rebase and the `drop` action.

Edit a Non-Recent Commit
4/15/2026

Use interactive rebase with the `edit` action to amend an older commit.

Partial Staging

Partial Staging

Git Pro Tips

4/15/2026

Stage only part of a file by using Git's interactive add mode.

Git Bisect

Git Bisect

Git Pro Tips

4/15/2026

Track down the commit that introduced a bug by walking history with `git bisect`.

Keep Pull Requests Small
4/15/2026

Smaller pull requests are easier to review and usually produce better feedback.

Backup Branch Before Rebase
4/15/2026

Create a backup branch before a risky rebase so recovery is cheap.