Skip to content

Instantly share code, notes, and snippets.

@GMNGeoffrey
Last active February 9, 2022 18:24
Show Gist options
  • Save GMNGeoffrey/0506ea63d543ed5ddc11dcf7b48fdb2e to your computer and use it in GitHub Desktop.
Save GMNGeoffrey/0506ea63d543ed5ddc11dcf7b48fdb2e to your computer and use it in GitHub Desktop.
git commands
# Copyright 2020 Google LLC.
# SPDX-License-Identifier: Apache-2.0
[submodule]
recurse = false
fetchJobs = 8
[push]
default = current
[alias]
sync = ! (git-update main && git gone)
gone = ! "git fetch -p && git for-each-ref --format '%(refname:short) %(upstream:track)' | awk '$2 == \"[gone]\" {print $1}' | xargs -r git branch -\
D"
new = "!f(){ \\\ngit checkout master && git checkout -b $1; \\\n}; f"
fake-merge = "!f(){ \\\ngit reset --soft $(git log --format=%B -n 1 | git commit-tree HEAD^{tree} -p HEAD^ -p $1); \\\n}; f"
br = for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%\
(color:reset) - %(contents:subject) (%(color:green)%(committerdate:relative)%(color:reset))'
amend = commit -a --amend --no-edit
co = "!f(){ \\\ngit checkout ${1?} && git submodule update; \\\n}; f"
# `git git foo` -> `git foo` typo fixer
git = "!f(){ \\\n git \"$@\"; \\\n}; f"
root = rev-parse --show-toplevel
prunelocal = "!f() { \\\n git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git bra\
nch -D; \\\n}; f"
ch = "!f() { \\\n git checkout \"$@\"; git submodule sync && git submodule update --init; \\\n}; f"
reword = commit --amend --only
[checkout]
defaultRemote = origin
[pull]
ff = only
[remote]
pushDefault = origin
[url "ssh://[email protected]/"]
pushInsteadOf = https://github.com/
#!/bin/bash
# Copyright 2020 Google LLC.
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail
BRANCH=$1
if [[ -n "$(git status --porcelain --ignore-submodules)" ]]; then
echo "Working directory not clean"
git status
exit 1
fi
git checkout "${BRANCH}"
git pull upstream "${BRANCH}" --ff-only
git submodule sync
git submodule update --init
if [[ -n "$(git status --porcelain --ignore-submodules=dirty)" ]]; then
echo "Working directory not clean after update"
git status
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment