66 Posts Tagged ‘git’ (Page 3)

(All tags.)


Git: An alias to speed up fixing merge conflicts

There you are, minding your own business, rebasing your branch and… surprise! A merge conflict!

Read more...

pre-commit: How to run hooks during a rebase

pre-commit uses Git’s hook system to run tools when you commit. Unfortunately, Git doesn’t run any hooks when making a commit during a rebase. This can lead to you rebasing a branch and not realizing some code needs fixing, at least not until your CI system runs pre-commit (say, with pre-commit.ci).

Read more...

Git: How to set up a global ignore file

Have you ever accidentally committed a bunch of junk created by your OS, like Thumbs.db files from Windows, or .DS_Store files from macOS? Or, have you joined a project, and for one of your first commits, added rules to the .gitignore file for your text editor’s project files? If so, this post is for you! You can avoid such pain or busywork by making a global ignore file.

Read more...

Git: automatically stash while rebasing or merging with autostash

Imagine you’re part way through making some changes, and you realize that you need to rebase or merge. You can:

Read more...

Git: How to undo commits

To errr is human, to undo computer can help.

Read more...

Git: How to automatically create upstream branches

You started a new branch, worked hard on initial commits, and you’re ready to send it for review. You try to push and:

Read more...

Git: How to clean up squash-merged branches

Git hosts offer a “squash merge” option that merges a reviewed branch by combining all its commits into one. This leads to a linear Git history on your main branch, which is easier to understand and refer back to code reviews.

Read more...

Git: How to alias “master” as “main”

The Git community is gradually moving the default branch name from “master” to “main”, because the term “master” is hurtful to some people as it refers to slavery.

Read more...

Git: How to enable autocorrect

By default, if you mistype a Git command, it will list similar commands that you might have meant:

Read more...

Git: Show and copy commit SHAs

You can use git rev-parse to show the SHA of the current Git commit:

Read more...

Git: Rebase stacked branches with --update-refs

When working on a feature, you might split it into several stacked branches, so you can merge each one separately. But updating such branches can be annoying since you have to manage them independently. Git 2.38 (2022-10-15) made this management easier with the new --update-refs option, which can rebase a stack of branches at once. Let’s look at a couple of examples.

Read more...

How to clean up unused code with Git

Projects often accumulate an amount of unused code. This cruft makes a prjoect harder to navigate, and can confuse future development or debugging.

Read more...

Git: Squash and rebase a branch with --keep-base

When you have a long-lived feature branch with many “work in progress“ commits, it can become tiresome to rebase it onto your main branch due to conflicts. You can end up fixing conflicts in the same areas of the same files over and over for multiple commits.

Read more...

Git: Run a command on all files in a repository

Occasionally it’s useful to run commands on all files in your repository, or those matching a pattern. This is possible by combining git ls-files and xargs.

Read more...

Git: compare generated files before and after changes with git diff

Once in a while, I have to make a change to many or all of my blog posts. For example, implementing opengraph meta tags.

Read more...

A Git Check for Missing Commits From a Remote

I recently add a pre-flight check to a devops project to ensure that all commits from the Git repository’s origin/master are present locally. This is to guard against developers accidentally reverting others’ deployed changes.

Read more...