Skip to content

Instantly share code, notes, and snippets.

@andresjesse
Last active September 10, 2024 00:21
Show Gist options
  • Save andresjesse/c4eea9c925520d374100a12a7aaea917 to your computer and use it in GitHub Desktop.
Save andresjesse/c4eea9c925520d374100a12a7aaea917 to your computer and use it in GitHub Desktop.

Clean local branches except master|main|develop:

git branch | grep -v '\*\|master\|main\|develop\|staging\|production' | xargs -n 1 git branch -D

Execute a command using an specific ssh key:

git -c core.sshCommand="ssh -i ~/.ssh/id_ed25519" push origin main

Clone a project using an specific ssh key:

git -c core.sshCommand="ssh -i ~/.ssh/id_ed25519" clone [email protected]

Set ssh key per project:

git config core.sshCommand "ssh -i ~/.ssh/id_ed25519"

Changing committer name and email per repository

git config user.name "John Doe" git config user.email "[email protected]"

Generate ssh PEM key for deploy keys

ssh-keygen -t rsa -m PEM

Reset author for all branch commits

git rebase -r --root --exec "git commit --amend --no-edit --reset-author"

Undo last local commit

$ git commit -m "Something terribly misguided" # (0: Your Accident)
$ git reset HEAD~                              # (1)
[ edit files as necessary ]                    # (2)
$ git add .                                    # (3)
$ git commit -c ORIG_HEAD                      # (4)

SSHFS

Mount remote folder using an specific ssh key

sshfs -o IdentityFile=/home/andres/.ssh/id_ed25519 USER@SERVER:/home/ubuntu .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment