Skip to content

Instantly share code, notes, and snippets.

@Jonalogy
Last active March 12, 2019 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jonalogy/bd7112ffd349f0ed65d876f6e83f26a1 to your computer and use it in GitHub Desktop.
Save Jonalogy/bd7112ffd349f0ed65d876f6e83f26a1 to your computer and use it in GitHub Desktop.
Useful Git Commands

git ls-files or git ls-tree -r master --name-only

List tracked files. Read more here


git rm --cached FILE_NAME

Untracks file from index source


git push origin --delete <branch_name>

Deletes a remote branch


git log --graph --oneline --decorate

Shows logs in a decorated graph


git diff --check

This checks if any git conflict markers still exists in your code

A git conflict marker is:

<<<<<<< HEAD
bar
=========
barz
>>>>>>> master

Directly Checking out a remote branch

git fetch
git checkout -b local_branch_name_to_assign origin/branch_you_want_to_checkout

Useful git diff option

Note: An individual -- operator is a git pathspec command.

  • Shows only the names of files with changes

    git diff --name-only <commit-to-be-compared with> <commit-used-to-compare>

  • Performing exlusion during a git diff. Read more Here

    git diff <commit-to-be-compared with> <commit-used-to-compare> -- . ':(exclude)file/to/exclude.txt'

  • Getting the differences only from a specific folder

    git diff branch_1 -- folder/subfolder branch_2 -- folder/subfolder


Git Tagging

git tag <tag_name> creates a tag

  • -m adds a message for the tag
  • -a creates an annotaes the tag with a tag object

git tag -d <tag_name> deletes specified tag locally

git push --delete origin <tag_name> deletes specified tag remotely

git push origin <tag_name> pushes a specific tag to remote

git push --tags pushes all tags to remote

Git Branch

git branch -vv Displays all local branches and shows the remote branches they are tracking.


Git Reset / Revert / Checkout

git reset <commits> Discards commits or number of commits from the HEAD, thus altering Git hitory.

git revert <commit> Reverses changes of the specified commit by creating a new commit with the inverse of the changes.

git checkout Checkout only sets the HEAD to one of the commits in history. It does not alter git history.

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