Git: Switching back to the previous branch
Using git checkout -
you can switch back to the branch you previously worked on.
(master) $ git checkout foobar
Switched to branch 'foobar'
(foobar) $ git checkout -
Switched to branch 'master'
(master) $
This also works with other commands like git merge
:
(master) $ git checkout foobar
Switched to branch 'foobar'
(foobar) $ git merge -
Merged branch 'master'
Related cards:
Git: How to configure git to push only your current branch
You can change which branches will be pushed when saying git push
. Our recommendation is to set it to current
.
From the git-config
documentation:
...
Git: How to rebase your feature branch from one branch to another
In a nutshell: Use git rebase --onto target-branch source-commit
-
target-branch
means "branch you want to be based on" -
source-commit
means "commit before your first feature commit"
Let's say my-feature-branch
...
Git: Advisory for cherry-picks to production branches
We often have a separate production branch that lags a bit behind the more cutting edge main branch. Sometimes you want to move some, but not all commits from main to production. This can be done with a git cherry-pick
.
However, this ma...
Git shortcut to rebase onto another branch
Inspired by recent "git shortcut" cards I figured it would be nice to have one of these for rebasing a few commits onto another branch. The usual notation is prone to of-by-one errors as you have to either specify the commit before the ones you ...
Force GitHub Pull Requests to update the diff against its target branch
When you have a Pull Request on GitHub that includes commits from another Pull Request, you will still see them after the "child" PR has been merged. Unfortunately, GitHub won't automatically update the diff (or commit list).
Here is what worked ...
Git: How to check out branches that exist on multiple remotes
So you're using multiple remotes that offer the same branch?
$ git branch -a | grep my-branch
remotes/something/my-branch
remotes/origin/my-branch
And when trying to check out that remote branch, it fails for you with an error li...
Git Rebase: How to squash/fixup/edit/... commits without actually rebasing (keeping the base)
Purpose:
Interactively rebase your current branch onto main
, keeping the original base commit (i.e. not rebasing onto main
directly).
Use Case:
Useful when you've branched off a long-lived feature branch and want to clean up your ...
Bookmarklet to facilitate generating new git branches for PivotalTracker Stories
This bookmarklet grabs a PivotalTracker story title, transforms it into a valid git branch name and automatically prepends your initials and an optional abbreviation (for better tab completion). It will output the following formats:
If you cancel...
How to revert features for deployment, merge back, and how to stay sane
Removing features and merging those changes back can be painful. Here is how it worked for me.\
tl;dr: Before merging back: reinstate reverted features in a temporary branch, then me...
Git: How to look at the stash
Browsing the git stash is a bit tricky. Here is how to see the changes without applying them:
git
command on the console
The following will give you the diff of the topmost stash item:
git stash show -u
...