Skip to content

Instantly share code, notes, and snippets.

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

GIT cheatsheet

https://gitexplorer.com/

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 git@github.com:username/repo-name.git to change origin to the new url (ssh style url shown here, use the https style like above if that is what you prefer.)

@see https://gist.github.com/mandiwise/5954bbb2e95c011885ff#gistcomment-1833787

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>

@see https://stackoverflow.com/questions/2765421/how-do-i-push-a-new-local-branch-to-a-remote-git-repository-and-track-it-too

Git Ignore files only locally

useful for drupal development.services.yml

git update-index --skip-worktree SOME_FILE

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

@see https://stackoverflow.com/questions/13630849/git-difference-between-assume-unchanged-and-skip-worktree

Remove untracked files safely

git clean -n - git clean -f

@see https://stackoverflow.com/a/64966/426193

List files with merge conflicts

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

@see https://stackoverflow.com/questions/3065650/whats-the-simplest-way-to-get-a-list-of-conflicted-files

Tags

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

@source https://stackoverflow.com/questions/5195859/how-to-push-a-tag-to-a-remote-repository-using-git

Create a pull request

@see https://www.atlassian.com/git/tutorials/making-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 https://github.com/name/name.git

How to undo (almost) anything with Git

https://github.blog/2015-06-08-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