Tuesday, November 27, 2012

Common Git commands

Not working with Git on a daily basis makes me forget commands from time to time.
Here's a personal reminder of a few that seem to pop from the stack on a random basis ... :)

  • Delete remote branch
    git push [nameOfRemoteRepo] --delete [nameOfRemoteBranch]
    e.g:
    git push origin --delete feature-branch-that-has-been-merged
  • Show fancy commit/branch tree
    git log --graph --pretty=oneline --abbrev-commit --decorate --all
  • Create tag and push to remote repo
    git tag [nameOfTheTag]
    git push --tags 
  • Delete tag and push to remote repo
    git tag -d [nameOfTheTag]
    git push origin :[nameOfTheTag] 
  • Change the last commit message (provided it has not been pushed yet)
    git commit --amend -m "new message goes here"
  • Create local branch that track a certain remote branch
    git checkout --track -b new_feature origin/development
  • Revert local non-staged tracked changes
    git checkout -- .
    and to remove untracked files
    git clean -df
  • Find what commit(s) that contains a certain commit message
    git log --oneline --grep="string to look for"
  • All commits after a certain date
    git log --oneline --after=2012-12-05
  • Forgot to add something to your last commit and want to avoid a stupid "I forgot these files" commit?
    git commit --amend --no-edit
  • Delete local and remote branch
    git branch -d name_of_local_branch
    git push origin :name_of_remote_branch 
  • Revert the last commit pushed to remote
    git reset HEAD~1 --hard
    git push -f

No comments:

Post a Comment