7 Tips for Using Git at the Job

Read these before asking your busy senior colleague

Albin Groen
Level Up Coding

--

1. Update commit message

Run this command to get into your predefined git editor with your previous commit message in focus that you can edit and then save again.

git commit --amend --no-verify

2. Update pushed commit message

To update a pushed commit you start rebasing from the commit before the commit you want change. This is tricky, although certainly possible.

git rebase -i [COMMIT_HASH]...pick my-commit-message > reword my-new-commit-message...git push --force

3. Browse entire commit history

Sometimes you want easily browse the entire git history in your code editor or IDE. Run one of the following commands for easily accomplishing this.

Using VSCode

git log | code -

Using Vim

git log | vim

4. Create new branch with your changes

You often might start out building on the master branch, but when it times to create a pr you need a separate branch. Here’s how to quickly create one.

git checkout -b my-new-branch

5. Delete your merged branch

It’s a good idea to keep your local clone of the repository as clean as possible. Delete your merged branch like this, and make it a habit for the future.

git branch -d my-merged-branch

6. Difference between 2 commits

Sometimes you need to see the difference you’ve committed your changes. You can do this by diffing 2 commit hashed against each other like this.

git diff [FIRST_COMMIT_HASH] [SECOND_COMMIT_HASH]

--

--

Hi! I’m Albin, a front-end developer from Sweden passionate about software development, design, and self-improvement.