配置用户git config –global user.name “姓名"git config –global user.email “邮箱"克隆仓库git clone <url>新建分支基于mastergit checkout -b new-branch-name -t master或git checkout -b new-branch-name origin/master拉取远程分支,创建切换到本地分支git checkout -b 本地分支 origin/远程分支 (采用此种方法建立的本地分支会和远程分支建立映射关系)建立两个分支的映射(将当前分支映射到远程的指定分支,注意切换到当前分支)git branch -u origin/远程分支切换分支git checkout branch-name查看本地状态git status查看本地修改内容git diff比较本地文件和远程文件的区别git diff origin/master 文件路径在本地提交代码某一文件git commit -m ‘提交信息’ filename.txt在本地提交所有文件git commit -m ‘提交信息’ -a更新分支到githubgit push origin new-branch-name删除本地已被合并的分支git fetch -p origin读取远程仓库修改git fetch远程更新后将改动纳入本地分支git rebase remote-branch删除远程分支git branch -r -d origin/branch-name或git push origin :branch-name拉取最新代码:git pull <remote> <branch>或git pull –rebase <remote> <branch>强制更新单个文件:1) git fetch2) git checkout origin/master – path/to/file放弃本地修改,强制更新1) git fetch –all2) git reset –hard origin/masterfetch使用:git fetch origin master:temp (采用此种方法建立的本地分支不会和远程分支建立映射关系)比较本地的仓库和远程参考的区别$ git diff temp合并temp分支到master分支$ git merge temp如果不想要temp分支了,可以删除此分支$ git branch -d temp