Skip to content

Instantly share code, notes, and snippets.

@danhodge
Last active November 22, 2021 13:31
Show Gist options
  • Save danhodge/148d4203da159957399b24fdc93c29d6 to your computer and use it in GitHub Desktop.
Save danhodge/148d4203da159957399b24fdc93c29d6 to your computer and use it in GitHub Desktop.
Git notes

Show Branches with Unpushed Commits

git log --branches --not --remotes --no-walk --decorate --oneline

Sync Local Branch with Remote After A Force Push To Remote

(or after your working copy of a branch gets out of sync with the remote branch for any reason)

git fetch

# discards local changes
git reset origin/<branch_name> --hard

# preserves local changes
git reset origin/<branch_name> --soft

Show Remote Branches Sorted By Latest Commit

# https://gist.github.com/jasonrudolph/1810768
for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ci %cr" $branch | head -n 1` \\t$branch; done | sort -r```

Debug Git/SSH Server Interactions

% GIT_SSH_COMMAND="ssh -vvv" git ...

Amend Commit Author

  1. Enter interactive rebase
  2. Choose 'edit' for for the commit(s) that need the author amended
  3. Initiate rebase
  4. foreach commit:
% git commit --amend --author="Firstname Lastname <email>" --no-edit
% git rebase --continue
  1. Force push branch

Switch to a Different Git Account

  1. Set local config in repo
git config user.name "<USERNAME>"
git config user.email "<EMAIL>"
  1. Change ~/.ssh/config to use other SSH key

  2. Stop ssh-agent

kill -9 ssh-agent
  1. Add other SSH key
ssh-add -K ~/.ssh/<KEY>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment