gitlab 基本指令

A little lookup for commands I use frequently

  1. Commit all edited files and add a message

    git commit -a -m “My commit”

  2. Add all new files

    git add .

  3. Perform a pull operation

    git pull REMOTENAME BRANCHNAME

  4. Perform a push operation

    git push REMOTENAME BRANCHNAME

  5. Prune all stale remote tracking branches

    git remote prune REMOTENAME

  6. Create a branch

    git branch BRANCHNAME

  7. View branches

    git branch

  8. Checkout a different branch

    git checkout BRANCHNAME

  9. Checkout a remote branch

    git checkout -b LOCALBRANCHNAME origin/REMOTEBRANCHNAME

  10. Merge the changes made in another branch in to the current branch

    git merge BRANCHNAME

  11. Delete a local branch

    git branch -d BRANCHNAME

  12. Delete a remote branch

    git push origin :BRANCHNAME

  13. Delete a remote branch (sexier syntax)

    git push origin –delete BRANCHNAME

  14. Scrap uncommitted state and return the working tree to the last committed state

    git reset –hard HEAD

  15. Delete the latest commit, and return to the one previous (one before HEAD)

    git reset –hard HEAD~1

  16. Return a single file to it’s last committed state

    git checkout – FILENAME
    git checkout HEAD FILENAME
    Git log
    git log
    git log –pretty=oneline
    git log –pretty=short

  17. Cherry pick commits and apply them to another branch (first grab the commit ID from the branch with said commit, then checkout the branch you wish to apply the commit to)

    git cherry-pick COMMIT-ID

  18. Stash uncommitted changes

    git stash save “message”

  19. Apply stashed changes somewhere

    git stash apply

  20. Stop a file being tracked (but do not delete it from the working directory, add to .gitignore etc after this)

    git rm –cached