Git 经常使用命令

配置用户

git config --global user.name "姓名"
git config --global user.email "邮箱"git

克隆仓库

git clone <url>github

新建分支

基于masterfetch

git checkout -b new-branch-name -t master
git checkout -b new-branch-name origin/masterurl

拉取远程分支,建立切换到本地分支
git checkout -b 本地分支 origin/远程分支 (采用此种方法创建的本地分支会和远程分支创建映射关系)code

创建两个分支的映射
(将当前分支映射到远程的指定分支,注意切换到当前分支)
git branch -u origin/远程分支rem

切换分支

git checkout branch-nameit

查看本地状态

git statusast

查看本地修改内容

git diffemail

比较本地文件和远程文件的区别

git diff origin/master 文件路径配置

在本地提交代码某一文件

git commit -m '提交信息' filename.txt

在本地提交全部文件

git commit -m '提交信息' -a

更新分支到github

git push origin new-branch-name

删除本地已被合并的分支

git fetch -p origin

读取远程仓库修改

git fetch

远程更新后将改动归入本地分支

git rebase remote-branch

删除远程分支

git push origin :branch-name

拉取最新代码:

git pull <remote> <branch>
git pull --rebase <remote> <branch>

强制更新单个文件:

1) git fetch
2) git checkout origin/master -- path/to/file

放弃本地修改,强制更新

1) git fetch --all
2) git reset --hard origin/master

fetch使用:

git fetch origin master:temp (采用此种方法创建的本地分支不会和远程分支创建映射关系)
比较本地的仓库和远程参考的区别
$ git diff temp
合并temp分支到master分支
$ git merge temp
若是不想要temp分支了,能够删除此分支
$ git branch -d temp
相关文章
相关标签/搜索