Skip to content

Instantly share code, notes, and snippets.

@andreassiegel
Last active November 20, 2019 07:59
Show Gist options
  • Save andreassiegel/915eaa39e7b1bd3008aa24c64c35b994 to your computer and use it in GitHub Desktop.
Save andreassiegel/915eaa39e7b1bd3008aa24c64c35b994 to your computer and use it in GitHub Desktop.
Command line cheat sheet

Command Line Cheat Sheet

Git

Housekeeping

Clean up branches

Remove branches that don’t have remote branches anymore.

$ git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done

Undo

Reset branch to a certain commit

$ git reset --hard {commitID}

Reset branch to the remote branch

Reset the local branch to the last state of the corresponding remote branch.

$ git reset --hard origin

Undo last commit

Revert the last commit, but keep the changes.

$ git reset HEAD~1

Delete a tag

Revert the last commit, but keep the changes.

$ git tag --delete  {tag}
$ git push --delete origin {tag}

Merging

Merge a remote branch

$ git merge origin/master

Squash Merge

Merge another branch and squash all changes into a single commit.

$ git merge --squash  {branchName}

Repository Templates

Syncing with the Repository Template

In order to stay in sync with a GitHub repository template, add the template repository as a remote:

$ git remote add template {[email protected]:{repoName}.git}
$ git remote update

Merge branches from the template into your repository:

$ git fetch
$ git merge --allow-unrelated-histories template/master

Alternatively, check out specific files from the template:

$ git fetch
$ git checkout template/master -- path/to/file

Misc

Check out some files from another branch

Pull in some files or directories from another branch into the current work directoy.

$ git checkout master ./{path}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment