Git
Articles and resources in the Git category. A full list of categories is also available.
Using Git restore to discard changes within a file
Article posted 11th May 2021 in Development and Git
git restore
is great, and one of its superpowers is its patch mode where we can restore parts of a file, rather than the whole file at once.Undelete a file with Git
Article posted 10th May 2021 in Development and Git
I’ve talked about how great
git restore
is, but I missed a really obvious use ofgit restore
: restoring a deleted file!Git restore to discard changes
Article posted 13th April 2021 in Development and Git
I no longer use
git checkout
to switch branches; I’ve also stopped using it to discard uncommitted changes: let me introducegit restore
!Using Git switch to change branches
Article posted 12th April 2021 in Development and Git
Since upgrading to macOS Big Sur, I’ve noticed that
git switch
works. But why do we need it when we’ve gotgit checkout
?Reset to a previous commit
Article posted 29th March 2021 in Development and Git
Have you ever made a bunch of commits on the wrong branch? I certainly have… Luckily, there’s an easy way to put things right.
On not setting an upstream for short-lived branches
Article posted 17th March 2021 in Development and Git
I only set upstream Git branches when I need to push and pull a lot, otherwise I prefer to write out my target branch manually. Here’s why…
Updating Netlify deployments when renaming your main Git branch
Article posted 15th March 2021 in Development and Git
When you rename your Git branch, you’re going to need to reconfigure any Netlify deployments that are set up to watch your old
master
branch.Setting an upstream Git branch
Article posted 26th February 2021 in Development and Git
There’s no such thing as syncing in Git, but setting an upstream branch is about as close as it gets.
How to rename the ‘master’ branch on GitHub
Article posted 25th February 2021 in Development and Git
So renaming
master
tomain
is a good idea, but how do we do it? Fortunately, it’s really straightforward if your repository lives on GitHub.Empathy, and renaming my ‘master’ branch to ‘main’
Article posted 24th February 2021 in Development and Git
I’ve noticed a move towards renaming the
master
Git branch. It’s a racially charged term and I’m very happy to switch frommaster
tomain
.Viewing the changes in a Git stash
Article posted 10th February 2021 in Development and Git
Naming stashes is a good idea if some time is likely to pass between stashing and picking up the work again, but sometimes we need even more info.
Deleting a stash in Git
Article posted 9th February 2021 in Development and Git
If you stash a lot, or need to apply a stash non-destructively you might eventually want to clear things down to keep your stash list tidy.
Applying a Git stash non-destructively
Article posted 8th February 2021 in Development and Git
You’ll almost always want to delete a stash when you apply it, but if for some reason you need to keep the stash around, Git lets you do that.
Giving your Git stash a name
Article posted 5th February 2021 in Development and Git
Naming your Git stashes can be really helpful, especially if you’re stashing a lot or saving a stash to come back to another day.
Choosing a stash from the list
Article posted 4th February 2021 in Development and Git
Viewing all of a Git repository’s stashes and choosing one from the list is the next step I took in my Git stash on the command line journey.
Getting started with Git stash
Article posted 3rd February 2021 in Development and Git
I’ve put it off for the longest time, but it turns out stashing changes with Git on the command line is surprisingly easy to get the hang of.
Splitting a hunk in Git’s patch mode
Article posted 15th September 2020 in Development and Git
When you enter Git’s patch mode, the chunks of code you’re offered to stage/skip can sometimes be too big. Here’s how splitting them works.
Staging different parts of the same file with Git
Article posted 14th September 2020 in Development and Git
Since moving to command line Git, I’ve avoided patch mode; it looked too complicated. Turns out it’s really not, and very much worth learning.
Searching for a Git commit by name with grep
Article posted 24th July 2020 in Development and Git
When you need to dig out a commit you made a long time ago, you’re going to need something a bit more powerful than a standard
git log
.A handy Git shortcut to fetch and prune
Article posted 8th July 2020 in Development and Git
I’m still writing my Git commands long-hand. Turns out a fetch and prune can be more concise than I’ve previously suggested, all without aliases.
Chaining Git commands
Article posted 7th July 2020 in Development and Git
Writing a sequence of Git commands is really handy and much quicker than running one, waiting for it to finish, writing the next, etc. Here’s how.
Pushing to a differently named branch on your remote
Article posted 29th June 2020 in Development and Git
When using Git, you’ll normally push work to an identically named branch on your remote, but what if you want to push to a different branch?
Keeping git status short
Article posted 22nd June 2020 in Development and Git
git status
is one of the Git commands I use the most, but I’ve always thought that it overshares. Well, I’ve found a way to make it more readable!Why I always raise a pull request on solo projects
Article posted 4th May 2020 in Development and Git
The whole point of a PR is to get feedback and approval on a piece of work from someone else before it’s published. But what if it’s just you?
How to rename a remote repo in Git
Article posted 10th February 2020 in Development and Git
Renaming a Git repository feels pretty fundamental – surely something will break? Well, worry no more – it turns out it’s a piece of cake!
How to diff branches in Git
Article posted 11th January 2020 in Development and Git
Turns out it’s pretty easy to look at the differences between two branches in Git. This is useful when coming back to a feature branch after a while.
Git rebase versus merge
Article posted 31st December 2019 in Development and Git
There are two ways to get a branch up to date with master before raising a PR: merge and rebase. Here are pros and cons with each.
Version tagging with Releases in GitHub Flow
Article posted 27th December 2019 in Development and Git
I’ve started using GitHub Flow for some projects and the process is much simpler than GitFlow, but one hurdle I encountered was tagging.
Simplifying branching and deployment with GitHub Flow
Article posted 14th December 2019 in Development and Git
GitFlow is great but it’s not quite right for every project. GitHub Flow is simpler and means I’ll publish a feature or fix as soon as it’s ready.
Adding files for a commit with asterisks
Article posted 1st October 2019 in Development and Git
It can be fiddly to stage files for a commit using Git on the command line. Or so I thought! I found a shortcut, so thought I’d write about it.
Why I’m not using Git aliases
Article posted 11th September 2019 in Development and Git
Git aliases are incredibly useful, but there are five good reasons I’ve decided not to make use of them.
Version control for articles and blog posts
Article posted 6th September 2019 in Development and Git
Git workflows like GitFlow are great, but how does publishing articles fit in when using a static site generator? Here’s how I’m doing it.
Changing editor for Git on the command line
Article posted 21st August 2019 in Development and Git
Something that has been bugging me since moving from a GUI to command line git has been the default editor for writing commit messages.
Fixing your last Git commit
Article posted 21st August 2019 in Development and Git
Since I’ve started using Git on the command line, there’s one ‘new’ thing that I’ve used more than any other: amending my most recent commit.
Changing your Git history
Article posted 26th July 2019 in Development and Git
This week I removed some files and data from my Git history. It was a bit of a learning curve, but here’s how I did it, step by step.
Getting to grips with Git
Article posted 26th June 2019 in Development and Git
I’ve been using Git for years and it’s finally time to make a concerted effort to move away from my GUI to the command line.