Skip to content

Instantly share code, notes, and snippets.

@jlmelville
Last active September 28, 2023 14:54
Show Gist options
  • Save jlmelville/0727eca29211f11478f3e4b06f79eece to your computer and use it in GitHub Desktop.
Save jlmelville/0727eca29211f11478f3e4b06f79eece to your computer and use it in GitHub Desktop.
fetching and merging forks
# Basic .gitconfig stuff
[core]
    editor = vim
[pull]
    rebase = false
# Enforce SSH
# https://stackoverflow.com/a/36500841
[url "ssh://git@github.com/"]
  insteadOf = https://github.com/
[url "ssh://git@gitlab.com/"]
  insteadOf = https://gitlab.com/
[url "ssh://git@bitbucket.org/"]
  insteadOf = https://bitbucket.org/
  
# Add ssh key
ssh-keygen -t ed25519 -C "<email>"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
# on WSL (and WSL2):
cat ~/.ssh/id_ed25519.pub | clip.exe
# Then paste in User > Settings > SSH and GPG keys > New SSH key

# one time setup of upstream fork tracking
git remote add upstream https://github.com/<upstream-username>/<repo>.git
git remote -v

# merging from upstream
git checkout master
git fetch upstream
# or git fetch --all ?
git merge upstream/master
git push

# create a new branch on github
git checkout <branch name>

# branch from another branch
# https://stackoverflow.com/questions/4470523/create-a-branch-in-git-from-another-branch
git checkout -b <new branch name> <source branch>
# do some work
git commit -am "message"
git push origin <new branch name>

# cherry pick commits to a new branch 
# https://poanchen.github.io/blog/2017/11/12/How-to-create-a-GitHub-pull-request-with-a-specific-commits
git checkout -b new-branch-name upstream/master
git cherry-pick <commit hash>
git cherry-pick <another commit hash>
git push -u origin new-branch-name

# https://blog.scottlowe.org/2015/09/04/checking-out-github-pull-requests-locally/
git fetch origin pull/<pr_id>/head:pr-<pr_id>
git checkout pr-<pr_id>

# rename a branch
git branch -m old-name new-name
git push origin :old-name new-name

# https://verbosemode.substack.com/p/8-amazing-aliases-to-make-you-more
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status

# briefer git log
git config --global alias.lol "log --graph --decorate --pretty=oneline --abbrev-commit"s
# list remote and local branches
git config --global alias.bra "branch -a  --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) %(color:blue)(%(committerdate:short)) [%(authorname)]' --sort=-committerdate"
# reset to head and undo everything locally
git config --global alias.fit '!git reset --hard && git clean -fdx'
# undo last commit
git config --global alias.uncommit 'reset --soft HEAD^'
# add and commit
git config --global alias.ac '!git add -A && git commit
# list aliases
git config --global alias.alias "config --get-regexp ^alias\."
# last commit
git config --global alias.last '!git --no-pager log -1 HEAD'


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