Git Tips

Useful commands

  • “git status -uno” – the untracked files will be ignored.
  • “git checkout HEAD — <a_file>” – revert the local change on <a_file>
  • “git checkout –track origin/<remote_branch_name>” – checkout a remote branch
  • “git stash” – very useful for the conflicts when pulling/merging.
    • git stash – stash current local changes into a stack.
    • git stash list – list all changes.
    • git stash apply – reapply the previous local change
  • “git show commit”  – show the details of the given commit.
  • “git remote show <remote_server>” – show the details of a remote server.
  • git log --graph --decorate --pretty=oneline --abbrev-commit” – better log command
  • git commit --amend --author="Philip J Fry <someone@example.com>" – amend commit
  • “git remote add upstream https://github.com/…” – add upstream of a fork and then use “git fetch upstream” to sync them
  • “git push -u origin remove_branch” – push local branch to remote.