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

Rename or Move a File
Git Noob Tips
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
Git Noob Tips
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
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
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
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
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
Git Pro Tips
Avoid accidental empty commit messages by upgrading Git and relying on the editor prompt.

Force With Lease Alias
Git Pro Tips
Create a short alias for `push --force-with-lease` so the safer option is easier to use.

Change Last Commit Author
Git Pro Tips
Amend the latest commit with a different author name and email.

Delete Local Branches in Bulk
Git Pro Tips
Remove all local branches except the main one with a single pipeline command.

Enable Fetch Prune
Git Pro Tips
Automatically remove local references to remote branches that were deleted upstream.

Prune Remote Tracking Branches
Git Pro Tips
Clean up stale remote-tracking branches after they disappear from the remote.

Squash Last Commits
Git Pro Tips
Use interactive rebase to squash your recent commits into one cleaner commit.

Reword a Commit Message
Git Pro Tips
Change the message of an older commit with interactive rebase and the `reword` action.

Drop a Commit
Git Pro Tips
Remove a commit from history with interactive rebase and the `drop` action.

Edit a Non-Recent Commit
Git Pro Tips
Use interactive rebase with the `edit` action to amend an older commit.

Partial Staging
Git Pro Tips
Stage only part of a file by using Git's interactive add mode.

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

Keep Pull Requests Small
Git Pro Tips
Smaller pull requests are easier to review and usually produce better feedback.

Backup Branch Before Rebase
Git Pro Tips
Create a backup branch before a risky rebase so recovery is cheap.
