During a typical day, I would change to the main branch, pull the latest from the remote, delete the merged branches. Over and over all day, every day of the work. Now instead of all that checkout and pulling, I made a Git JERK!
Continue reading “Git Jerk”Tag: git
Git -Xours -Xtheirs arguments
Git provides a helpful argument to prefer one branch or the other to “clobber” merge conflicts:
git merge main -Xours
git merge main -Xtheirs
I always get confused what the “X” means. I always assume “X” means mark which branch to clobber. Like “X” out their
branch. Or “X” out our
branch. Please wipe this mnemonic from your brain!
“X” means “PREFER”
“PREFER” the changes in their
branch (-Xtheirs
) or “PREFER” the changes in our
branch (-Xours
).
Jeez!
Links
Git Rollback Alias
Related to the Alias for Git sanity post from a few years back, recently added another to ~/.gitconfig
[alias]
revert-merge = !git revert -m 1 $1
rollback-merge = revert-merge
Where $1
is the commit hash. This only works for rollback of a merge commit on the main branch.
Git Branch Print to CLI
Since the release of Git 2.16, the git branch
command runs as paged executable instead of printing the branches to the console. To revert back to the old way of printing branches to the console, update your ~/.gitconfig
as follows:
[pager] branch = false
Git Automatically Resolve Conflicts
$ git merge -Xours branch-name $ git merge -XTheirs banch-name
Comes in really handy for sweeping updates, like running eslint --fix
on an entire code base or merging package-lock.json
.
Alias for Git sanity
Git command line is pretty confusing. Here are some aliases that I found helpful that normalize it with other command line commands and add a little bit better context.
Open global .gitconfig
file:
$ open ~/.gitconfig
If there isn’t an [alias]
section already, add one:
[alias] cd = checkout ll = branch ls = branch delete-merged = !git branch --merged | egrep -v \"(^\\*|master|development)\" | xargs git branch -d mk = checkout -b new-up = !git push -u origin `git symbolic-ref --short HEAD` stage = add unstage = reset HEAD
Update 2018-07:
To set VS Code as the default editor for commit and merge messages:
[core] editor = code --wait