Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
[GIT cheatsheet] #tags: git, cheatsheet

GIT cheatsheet

Git log remote branch

$ git log origin/master

Get remote repo url

git config --get remote.origin.url

Remove untracked files (new files)

git clean -f -d

Migrate repository from bitbucket (or something else) to github

Use to upper right shortcut "+ > Import repository"

You can then change your local repo to point at the new origin. git remote -v to print the current settings git remote set-url origin to change origin to the new url (ssh style url shown here, use the https style like above if that is what you prefer.)


Push local branch to remote

$ git push -u origin <branch>

$ git push -u origin <local-name>:<remote-name>

Remove remote branch

$ git push origin --delete <branch_name>


Git Ignore files only locally

useful for drupal

git update-index --skip-worktree SOME_FILE

git update-index --no-skip-worktree SOME_FILE


Remove untracked files safely

git clean -n - git clean -f


List files with merge conflicts

git diff --name-only --diff-filter=U



Tag current commit

git tag -a v1.6 -m "Milestone 1.6"

Push tag(s) to remote

To push a single tag:

git push origin <tag_name>

And the following command should push all tags (not recommended):

git push --tags


Create a pull request


Usually for a repo you don't own:

  • create a fork
  • clone & create a dedicated branch
  • push the branch with new commit
  • ask for a pull request on the initial repo

Remove remote branch

git push origin -d branchName

Add another remote origin

git remote add origin

How to undo (almost) anything with Git

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