Skip to content

Instantly share code, notes, and snippets.

@etelford
Last active August 4, 2020 23:06
Show Gist options
  • Save etelford/1436cd7c371961e41c68 to your computer and use it in GitHub Desktop.
Save etelford/1436cd7c371961e41c68 to your computer and use it in GitHub Desktop.
Various git snippets

Branches

Create a new branch from a specific commit

git checkout -b {new_branch_name} {hash}

Delete local branch

git branch -d {branch_name}

Delete remote branch

git push origin --delete {branch_name}

Remove local references to deleted remote branchs

git fetch --prune

Reset a local branch based on the remote version of that branch

git reset --hard origin/{branch_name}

Tags

Delete a local tag

git tag -d tagname

Delete a remote tag

git push origin :tagname

Cherry Picking

Abort a cherry pick operation

git cherry-pick --abort

Continue a cherry pick operation

git cherry-pick --continue

Force overwriting local files with any files being picked

for a single commit

git cherry-pick --strategy=recursive -X theirs {hash}

for a range of commits

git cherry-pick --strategy=recursive -X theirs {start_hash}^..{end_hash}

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