Things I Learned #17: Another git trick

1 minute read til learning   git   command-line Comments

I work in git every day, whether for work, this blog, or other projects. I've never really gotten the hang of visual clients, although sometimes I'll use SourceTree; it's rare. Most of my time is spent in a terminal, using the command line interface.

I have several posts in development for this blog at any given time. Interesting Links posts get built throughout the week, and I've always got a TIL or article in progress. When I first moved to Jekyll as my blogging platform earlier this year (post coming soon), I worked on everything directly in the main branch of my GitHub repository. I figured it was only me, so what's the worst thing that could happen?

After accidentally publishing things that I was still working on because I was trying to get something else published, I decided to use a branching strategy and create PRs for each post. Now, each post in this blog starts in a branch. For example, the branch for this post has the super-clever name, "til17". I'm also working on the upcoming Interesting Links of the Week in a branch called "ilotw52."

While I'm on the subject of branch names, we use the always descriptive method of naming branches by the ID number of a card in Azure DevOps at my client. That means we have a ton of branches called: "feature/44632" and "feature/44876". Easy to remember, right? Ok, so enough about branch names. Is this going somewhere?

Ok, so enough about branch names, is this going somewhere?

TIL

I'm not sure where or when I learned this, but if you're in "branch A" and you want to change to the LAST branch you were in quickly, it's as simple

git checkout -
If you were in main then changed to "feature/43567" and want to get back to main, sure you COULD type:
git checkout main
or if you were in the main branch and wanted to get back to that one feature branch you were working on...what was the number again? It doesn't matter; use the shortcut:
git checkout -

I know this isn't necessarily groundbreaking, but if it saves me a few keystrokes each day, I'm ok with it.

Updated:

Comments