官方文档地址

本地代码上传到远程仓库的master

  1. git init //初始化本地代码,新建.git 文件
  2. git status // 查看本地文件与服务的差别
  3. git add . //讲所有文件添加到本地仓库中
  4. git commit -m "添加本次提交记录" // 为本次记录添加说明
  5. git remote add origin https://domain.com // 讲本地代码与远程仓库做关联(远程仓库存在的情况下)
  6. git pull --rebase origin master // 讲代码定位到origin master 主仓库下
  7. git push -u origin master // 推送代码到master分支

本地创建分支并上传到远程服务器

  1. git branch // 查看本地分支
  2. git branch -a // display all the branch including remote branch
  3. git checkout -b dev // switch branch to dev
  4. git push origin <local branch name>:<remote branch name> // link local branch to remote branch and push to the serve
  5. git push origin:<remote branch name> // delete remote branch

删除本地分支

  1. git branch -d 分支名

拉取远程分支到本地

  1. git pull origin/dev // get dev branch to local branch

pull a different branch and switch to the branch

  1. git checkout -b dev origin/dev

合并本地分支到master分支

  1. git checkout master // switch to master branch
  2. git pull origin master // get the newest code in the master branch
  3. get merge dev // merge dev code to the local branch
  4. git push origin -d dev // delete dev branch

放弃文件更改

  1. // 1. if you did not use git add command to cache the code
  2. git checkout --filename // discard the filename modify
  3. git checkout . // discard all the modified content in this repository
  4. // 2. if you use git add command to cache the code
  5. git reset HEAD filename // discard the filename
  6. git reset HEAD // discard all the modified file
  7. // 3. if you already use git commit command to cache the code
  8. git reset --hard HEAD^ // go back to the last commit status
  9. git reset --hard commit id // go back to any commit status, commitId is a serial string made by git itself

tags

  1. git push origin --tags // tags发送到服务器
  2. git tag // inspect all the tag
  3. git show v0.0.1 // show the descripiton info
  4. git tag -d v0.0.1 // delete v0.0.1 tag
  5. git tag -a v0.0.1 -m 'descript this tag'

progit.pdf

progit_v2.1.34.pdf