A work-in-progress list of my favorite Git commands

I was planning to write an article as a reference for the Git commands I use the most. In the following list you see these commands and an explanation for each one of them:

  • Discards all local changes to all files:
    • git reset –hard
  • Clones an online repository:
    • git clone URLOfTheRepository
  • Merge master into a feature branch. A practical way to refresh the feature branch with changes that were made in other feature branches and merged to master:
    • git rebase master
  • Create a new feature branch:
    • git checkout -b BranchName
  • Delete a branch locally:
    • git branch -D BranchName
  • Connect a remote branch to an existing local branch:
    • git branch –set-upstream-to=origin/TheNameOfTheRemoteBranch TheNameOfTheLocalBranch
  • Make a new branch online, based on the offline branch
    • git push –set-upstream origin TheNameOfTheLocalBranch
  • Revert the last commit you made:
    • git revert head
  • Create a new feature branch from cmd:
    • git checkout -b TheNameOfTheLocalBranch
  • Delete a remote branch:
    • git push origin –delete TheNameOfTheLocalBranch
comments powered by Disqus