seo营销培训,企业网站快速优化排名,口腔建立网站,做商城外贸网站本博客的环境是 Ubuntu/Linux 文章目录 集中式与分布式的区别远程仓库新建远程仓库克隆远程仓库向远程仓库推送从远程仓库拉取 配置Git忽略指定文件给命令配置别名 标签管理创建标签操作标签 多人协作本地分支与远程分支连接场景一场景二 集中式与分布式的区别
引荐自关于Git这…本博客的环境是 Ubuntu/Linux 文章目录 集中式与分布式的区别远程仓库新建远程仓库克隆远程仓库向远程仓库推送从远程仓库拉取 配置Git忽略指定文件给命令配置别名 标签管理创建标签操作标签 多人协作本地分支与远程分支连接场景一场景二 集中式与分布式的区别
引荐自关于Git这一篇就够了 Git是分布式版本控制系统还有 svncvs 的集中式版本控制系统 区别在于集中式版本控制在每次写代码时都需要从服务器拉取一份下来并且如果服务器丢失那所有的数据就丢失了本地只保存当前的版本信息。集中式将代码都放在一个服务器上集中管理本地的所有回滚等操作都需要服务器支持
而分布式版本控制通常也有一台充当 “中央服务器” 的电脑但当你从主仓库拉取一份代码后你的电脑也成为了服务器相当于每个人的电脑都是一台服务器都有完整的版本库可以自由的在本地进行回滚修改提交完成开发后合并到主仓库即可。
集中式都有一个主版本号所有的版本迭代都以这个版本号为主而分布式因为每个客户端都是服务器所以没有固定的版本号而使用由哈希算法生成的一个 commit id用于回滚操作。同时也有一个master主仓库是一切分支仓库的主仓库我们可以推送提交到master并合并到主仓库上主仓库的版本号会迭代一次。我们客户端上的 git 版本号无论迭代多少次都跟master无关只有合并时master才迭代一次
远程仓库
上述说到Git 是分布式版本控制有一个“中央服务器”我们熟知的 GitHub 和 Gitee 就充当了 “中央服务器”的作用。我们可以在上面创建仓库这就是远程仓库然后在本地机器上拉取一份代码下来在本地进行开发开发完成后提交给远程仓库进行合并。 本篇博客以Gitee为例
新建远程仓库
Gitee 点击“创建”如此就创建了一个远程仓库 克隆远程仓库
克隆/下载远程仓库到本地需要使用git clone命令
git clone [远程仓库链接]链接的获取在仓库页面右上角的“克隆/下载” 链接最常用的是 —— HTTPS 和 SSH
使用 HTTPS 方式没有要求直接使用命令即可
ubuntuVM-12-11-ubuntu:~/lesson/gitcode$ git clone https://gitee.com/bao-bao-hai-mian/remote_git.gitCloning into remote_git...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
Receiving objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
ubuntuVM-12-11-ubuntu:~/lesson/gitcode$ ll
total 12
drwxrwxr-x 3 ubuntu ubuntu 4096 Sep 17 16:09 ./
drwxrwxr-x 10 ubuntu ubuntu 4096 Sep 15 14:48 ../
drwxrwxr-x 3 ubuntu ubuntu 4096 Sep 17 16:09 remote_git/
ubuntuVM-12-11-ubuntu:~/lesson/gitcode$ cd remote_git/
ubuntuVM-12-11-ubuntu:~/lesson/gitcode/remote_git$ ll
total 20
drwxrwxr-x 3 ubuntu ubuntu 4096 Sep 17 16:09 ./
drwxrwxr-x 3 ubuntu ubuntu 4096 Sep 17 16:09 ../
drwxrwxr-x 8 ubuntu ubuntu 4096 Sep 17 16:09 .git/
-rw-rw-r-- 1 ubuntu ubuntu 954 Sep 17 16:09 README.en.md
-rw-rw-r-- 1 ubuntu ubuntu 1315 Sep 17 16:09 README.mdSSH 使用了公钥加密和公钥登录机制使用该协议需要将本地的公钥设置到远程仓库中由 Git 进行管理
首先要生成本地的公钥和私钥。在用户主目录下查看是否有.ssh目录再看该目录下是否有id_rsa(私钥) 和 id_rsa.pub(公钥)。如果没有使用如下命令创建
ssh-keygen -t rsa -C 邮箱
#后续一路回车即可将公钥配置到远程仓库中
cat id_rsa.pub
#再复制公钥回到Gitee点击头像 - 设置 - SSH公钥 - 粘贴公钥 如此就可以使用 SSH 方式克隆远程仓库了
ubuntuVM-12-11-ubuntu:~/lesson$ git clone gitgitee.com:bao-bao-hai-mian/remote_git.gitCloning into remote_git...
The authenticity of host gitee.com (180.76.198.77) cant be established.
ED25519 key fingerprint is SHA256:ULzij2u99B9eWYFTw1Q4ErYG/aepHLbu96PAUCoV88.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added gitee.com (ED25519) to the list of known hosts.
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (4/4), 2.10 KiB | 2.10 MiB/s, done.当我们从远程仓库克隆后实际上 Git 会自动把本地的 master 分支和远程的 master 分支连接起来并且远程仓库的默认名称是 origin。 在本地我们可以使用 git remote命令查看远程仓库信息
git remote #显示远程库信息
git remote -v #显示更详细信息ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git remote
origin
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git remote -v
origin gitgitee.com:bao-bao-hai-mian/remote_git.git (fetch)
origin gitgitee.com:bao-bao-hai-mian/remote_git.git (push)使用 git remote -v显示有fetch(拉取)和push(推送)的地址如果没有推送/拉取权限就看不到相应的地址
向远程仓库推送
推送的命令如下
git push [远程主机名] [本地分支名]:[远程分支名]
#例
git push origin master:master#如果本地分支与远程分支相同则可以简短一点
git push [远程主机名] [分支名]在推送前要对仓库的user.name和user.email进行配置与远程仓库的用户名和邮箱相同
git config -l #以列表形式查看配置
git config user.name 用户名
git config user.email 邮箱#还可以带上 --global选项使该配置在本机器所有仓库生效
git config --global user.name 用户名
git config --global user.email 邮箱接下来完成开发后就可以正常add添加、commit提交、push推送三板斧
示例在本地创建file.txt并编辑内容然后推送到远程仓库
#新建并编辑文件
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ vim file.txt
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ cat file.txt
hello git
#添加到暂存区
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git add .
#提交到本地版本库
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git commit -m add file:file.txt
[master 4b2de81] add file:file.txt1 file changed, 1 insertion()create mode 100644 file.txt#推送到远程仓库
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git push origin master:master
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 2 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 317 bytes | 317.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag 7c4399be
To gitee.com:bao-bao-hai-mian/remote_git.git523bb3a..4b2de81 master - master如果是 SSH 协议不需要每一次推送都输入密码方便推送操作。但如果是 HTTPS 协议每次推送时需要输入口令
从远程仓库拉取
如果远程仓库有修改本地仓库并不会随着改变本地仓库类似于对远程仓库的一次拷贝后续若没有推送操作双方并不会影响 为了保持本地仓库和远程仓库的一致性基于最新的版本进行开发可以进行拉取操作
git pull [远程主机名] [远程分支名]:[本地分支名]
#若远程与本地分支名相同则可以简写
git pull [远程主机名] [分支名]配置Git
忽略指定文件
在日常开发中我们有些文件不想或不应该提交到远端比如保存了数据库密码的配置文件Git 使用.gitignore文件实现 在 Git 工作区的根目录下创建一个 .gitignore文件然后把要忽略的文件名填进去Git 就会自动忽略这些文件
Gitee在创建远程仓库的时候就可以手动选择生成.gitignore文件
.gitignore文件使用如下
可以直接指定要忽略的文件名*.so表示忽略所有以.so结尾的文件!文件名表示不忽略该文件 上述文件表明忽略所有以.so和.conf结尾的文件但不忽略b.so指定忽略a.txt。
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ touch .gitignore
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ vim .gitignore
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ touch a.txt lib.so b.so
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git add .
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git commit -m test .gitignore
[master 19ee94c] test .gitignore2 files changed, 10 insertions()create mode 100644 .gitignorecreate mode 100644 b.so可以看到最后也确实忽略了a.txt和lib.so 不过 Git 也支持强制添加
git add -f [文件名] #带-f选项表示强制添加Git 还支持检查一个文件是否被忽略
git check-ignore -v [文件名]ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git check-ignore -v lib.so
.gitignore:3:*.so lib.soGit 会告诉我们.gitignore的第3行规则忽略了该文件
给命令配置别名
实际使用 Git 命令时有些命令较长Git 支持对命令进行简化
git config alias.[别名] [命令]#带上 --global选项使得配置所有仓库生效
#例
git config --global alias.st status
git config --global alias.last log -l标签管理
Git 标签(tags) 是一种用于标记特定提交的机制通常用于标识重要的版本点例如发布版本。Git 标签是固定的不会随着提交的改变而改变可以帮助我们在项目的历史中轻松找到重要的节点 相比于难以记住的commit idtag很好的解决了这个问题因为tag一定要给一个让人容易记住且有意义的名字。当我们需要回退到某个重要版本时直接使用标签就能很快定位到
创建标签
#会给当前分支的最近一次提交打上标签
git tag [标签名] #查看所有标签
git tag#给指定commit id 打上标签
git tag [标签名] [commit id]#查看标签信息
git show [标签名]#创建带说明的标签-a指定标签名-m指定描述
git tag -a [标签名] -m 描述 [commit id] 示例
#删除一些文件
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ rm a.txt b.so lib.so
#添加提交
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git add .
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git commit -m rm files
[master 7637b05] rm files1 file changed, 0 insertions(), 0 deletions(-)delete mode 100644 b.so
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git log
commit 7637b05a643918778b562c0effc1135c6d803ab8 (HEAD - master)
Author: bao-bao-hai-mian 1076847758qq.com
Date: Tue Sep 17 21:22:56 2024 0800rm files
#给最近的一次提交打上标签
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git tag -a v1.0 -m rm files
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git tag
v1.0
#查看标签信息
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git show v1.0
tag v1.0
Tagger: bao-bao-hai-mian 1076847758qq.com
Date: Tue Sep 17 21:24:12 2024 0800rm filescommit 7637b05a643918778b562c0effc1135c6d803ab8 (HEAD - master, tag: v1.0)
Author: bao-bao-hai-mian 1076847758qq.com
Date: Tue Sep 17 21:22:56 2024 0800rm filesdiff --git a/b.so b/b.so
deleted file mode 100644
index e69de29..0000000操作标签
如果标签打错了也可以删除
git tag -d [标签名]因为创建的标签都只存储在本地不会自动推送到远程所以可以在本地安全删除。 如果要推送某个标签到远程使用命令
git push origin [标签名]ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git push origin v1.0
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 2 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (7/7), 741 bytes | 741.00 KiB/s, done.
Total 7 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag 7f4c2899
To gitee.com:bao-bao-hai-mian/remote_git.git* [new tag] v1.0 - v1.0成功推送后远程也可以看到标签 若本地有很多标签也可以一次性推送
git push origin --tags 如果误推送了错误的标签需要
在本地删除标签将删除推送给远程
git tag -d [标签]
git push origin :[本地标签]
#例推送时要指明标签在.git文件中的路径
git tag -d v1.0
git push origin :refs/tags/v1.0多人协作
Git 的分布式版本控制正是服务于多人协作 在实际开发中每个用户都有自己的gitee/github账号如果要多人进行协同开发必须要将用户添加进开发者用户才有权限进行代码提交
实际开发中在任何情况下其实都不允许直接在 master分支上修改代码这是为了保证主分支的稳定所以在开发新功能时。常常会新建其他分支供开发时迭代使用 在 Gitee上也可以很简单的创建新分支
接下来通过两个用户分别在Linux和Windows上针对同项目进行协作开发 首先就是克隆远程仓库 双端都使用如下命令
git clone [远程仓库链接]如果远程仓库创建了新的分支可以通过 Git 拉取到本地
git pull [远程仓库] [远程分支]:[本地分支]#拉取远程仓库的新分支
git pull origin
#拉取(更新)远程仓库某分支的内容到本地分支
git pull origin dev:dev查看仓库分支
git branch #只能查看本地分支
git branch -r #查看远程仓库分支
git branch -a #远程和本地都查看git branch -v #查看本地分支信息
git branch -vv #在显示信息的基础上额外显示连接的远程分支本地分支与远程分支连接
将本地分支和远程分支连接可以简化我们在拉取和推送时的命令 如果没有建立连接那么拉取和推送时都需要输入完整命令
git pull [远程仓库] [远程分支]:[本地分支]
git push [远程仓库] [本地分支]:[本地分支]而建立连接后例如本地dev和远程dev建立连接那么在本地dev拉取和推送只需简单的命令
git pull
git push建立连接有两种方式
创建本地分支时指明连接的远程分支
git checkout -b [本地分支] [远程分支]
#例
git checkout -b dev origin/dev本地分支创建完后在指明连接
git branch --set-upstream-to[远程分支] [本地分支]
#例
git branch --set-upstream-toorigin/dev dev使用如下命令可以查看连接情况
git branch -vv ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git branch -vv
* dev 4b2de81 [origin/dev] add file:file.txtmaster 4b2de81 [origin/master] add file:file.txt场景一
如果两个用户都对本地仓库的file.txt做修改并先后提交推送会发生什么 假设Linux用户先完成开发并推送至远程仓库
#file.txt原先的内容
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ cat file.txt
hello git
#开发
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ vim file.txt
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ cat file.txt
hello git
coding on Linux...
#添加提交推送
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git add .
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git commit -m md file.txt:add one line
[dev 62451e5] md file.txt:add one line1 file changed, 1 insertion()
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git push origin dev:dev
Username for https://gitee.com: bao-bao-hai-mian
Password for https://bao-bao-hai-miangitee.com:
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 2 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 292 bytes | 292.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag c4458a8a
To https://gitee.com/bao-bao-hai-mian/remote_git.git4b2de81..62451e5 dev - dev此时在远程仓库的dev分支下也能看到修改
此时再在Windows上进行开发并推送
#查看file.txt原先内容
Lenovoljh MINGW64 ~/Desktop/code/remote_git (dev)
$ cat file.txt
hello git
#完成开发
Lenovoljh MINGW64 ~/Desktop/code/remote_git (dev)
$ cat file.txt
hello git
coding on Windows...
#添加提交推送
Lenovoljh MINGW64 ~/Desktop/code/remote_git (dev)
$ git add .
Lenovoljh MINGW64 ~/Desktop/code/remote_git (dev)
$ git commit -m md file.txt:add one line
[dev 72df7f6] md file.txt:add one line1 file changed, 1 insertion()
Lenovoljh MINGW64 ~/Desktop/code/remote_git (dev)
$ git push origin dev:devTo https://gitee.com/bao-bao-hai-mian/remote_git.git! [rejected] dev - dev (fetch first)
error: failed to push some refs to https://gitee.com/bao-bao-hai-mian/remote_git.git
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: git pull before pushing again.
hint: See the Note about fast-forwards in git push --help for details.但是此时因为Linux用户先一步完成开发并推送到远程仓库导致远程仓库和Windows的内容不同推送失败Git也给出了报错信息——“更新被拒绝因为远程仓库有本地仓库没有的东西这通常是因为另一个用户推送了相同的分支建议先使用git pull” 所以建议在推送前先拉取一下远程仓库同步一下数据
#从远程仓库拉取内容
Lenovoljh MINGW64 ~/Desktop/code/remote_git (dev)
$ git pull
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 272 bytes | 22.00 KiB/s, done.
From https://gitee.com/bao-bao-hai-mian/remote_git4b2de81..62451e5 dev - origin/dev
Auto-merging file.txt
CONFLICT (content): Merge conflict in file.txt
Automatic merge failed; fix conflicts and then commit the result.
#有提示产生了合并冲突
Lenovoljh MINGW64 ~/Desktop/code/remote_git (dev|MERGING)
$ cat file.txt
hello gitHEAD
coding on Windows...coding on Linux...62451e5e20daec9dec13e9243719e8fce343f8efGit提示产生了合并冲突我们需要手动更改代码再提交推送。 注意产生了合并冲突在解决冲突后一定要记得再提交推送一次
#解决了合并冲突
Lenovoljh MINGW64 ~/Desktop/code/remote_git (dev|MERGING)
$ cat file.txt
hello git
coding on Linux...
coding on Windows...
#推送三板斧
Lenovoljh MINGW64 ~/Desktop/code/remote_git (dev|MERGING)
$ git add .
Lenovoljh MINGW64 ~/Desktop/code/remote_git (dev|MERGING)
$ git commit -m solve the merge conflict
[dev ab49781] solve the merge conflict
Lenovoljh MINGW64 ~/Desktop/code/remote_git (dev)
$ git push
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 16 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 567 bytes | 567.00 KiB/s, done.
Total 6 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag 7b4c81a4
To https://gitee.com/bao-bao-hai-mian/remote_git.git62451e5..ab49781 dev - dev远程仓库可以看到最终结果
由此两名开发者已经可以进行协同开发了不断的git pull/add/commit/push遇到冲突就手动解决再推送 要想看到小伙伴的代码只需要pull一下即可 最后虽然是在分支上进行多人协作开发但最终目的还是将开发后的代码合并到master上让我们的项目运行最新的代码 接下来是建议流程
切换到master先git pull拉取最新内容在切换到dev合并master分支如果有冲突解决冲突最后切换到master合并dev最后推送到远程仓库
#切换到master拉取最新内容
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git checkout master
Switched to branch master
Your branch is up to date with origin/master.
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git pull
Already up to date.
#切回dev合并master有冲突解决冲突
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git checkout dev
Switched to branch dev
Your branch is up to date with origin/dev.
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git merge master
Already up to date.
#切回master合并dev最后推送至远程仓库
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git checkout master
Switched to branch master
Your branch is up to date with origin/master.
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git merge dev
Updating 4b2de81..ab49781
Fast-forwardfile.txt | 2 1 file changed, 2 insertions()
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git add .
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git commit -m merge dev
On branch master
Your branch is ahead of origin/master by 3 commits.(use git push to publish your local commits)
nothing to commit, working tree clean
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git push
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag 644090b5
To https://gitee.com/bao-bao-hai-mian/remote_git.git4b2de81..ab49781 master - master最后在远程仓库的master分支也能看到修改后的内容 开发完成后就可以将dev分支删除了 远程仓库删完分支后在本地依然还能看到远程分支
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git branch -adev
* masterremotes/origin/HEAD - origin/masterremotes/origin/devremotes/origin/master需要使用命令来删除
git remote prune [远程仓库]ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git remote prune origin
Pruning origin
URL: https://gitee.com/bao-bao-hai-mian/remote_git.git* [pruned] origin/dev
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git branch -adev
* masterremotes/origin/HEAD - origin/masterremotes/origin/master可以看到远程仓库的dev被删除了最后删除本地的dev分支即可
总结一下在同一分支下进行多人协作的工作模式如下 首先可以试图使用 git push origin [分支] 推送自己的修改如果推送失败则因为远程分支比本地更新需要先git pull拉取新内容如果合并有冲突则解决冲突并在本地提交没有冲突或者解决完冲突后再用git push origin [分支]推送就能成功功能开发完成后使用建立的流程使得master合并开发分支并推送最后删除开发分支 场景二
一般情况下如果有多需求需要多人同时进行开发并不会在一个分支上进行多人开发而是一个需求或一个功能点就创建一个feature分支 现在同时有两个需求需要开发所以需要两个用户各自创建一个分支来完成开发 本次展示在本地创建分支再通过推送的方式发到远端 Linux用户
#创建并切换feature-1分支
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git checkout -b feature-1
Switched to a new branch feature-1
#完成需求开发
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ vim function1
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ cat function1
demand1 Done!
#推送三板斧
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git add .
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git commit -m complete demand1
[feature-1 4898bf6] complete demand11 file changed, 1 insertion()create mode 100644 function1
#因为远程没有仓库所以可以在推送时指明建立
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git push --set-upstream origin feature-1
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 2 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 285 bytes | 285.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag f542d8bc
remote: Create a pull request for feature-1 on Gitee by visiting:
remote: https://gitee.com/bao-bao-hai-mian/remote_git/pull/new/bao-bao-hai-mian:feature-1...bao-bao-hai-mian:master
To https://gitee.com/bao-bao-hai-mian/remote_git.git* [new branch] feature-1 - feature-1
Branch feature-1 set up to track remote branch feature-1 from origin.因为远程仓库并没有feature-1分支可以有以下两种方式
指定推送远程仓库会创建指定分支
git push [远程仓库] [本地分支]:[远程分支]
#例
git push origin feature-1:feature-1但是此时只是创建远程分支并没有建立连接建立连接可以简化拉取和推送的命令 建立连接
git branch --set-upstream-to[远程分支] [本地分支]
#例
git branch --set-upstream-toorigin/feature-1 feature-1推送时直接建立连接
git push --set-upstream [远程仓库] [本地分支]:[远程分支]
#例若本地和远程分支名相同可简写
git push --set-upstream origin feature-1Windows
#创建并切换分支
$ git checkout -b feature-2
Switched to a new branch feature-2
#完成需求开发
Lenovoljh MINGW64 ~/Desktop/code/remote_git (feature-2)
$ cat funciton2
demand2 Done!
#三板斧
Lenovoljh MINGW64 ~/Desktop/code/remote_git (feature-2)
$ git add .
Lenovoljh MINGW64 ~/Desktop/code/remote_git (feature-2)
$ git commit -m complete demand2
[feature-2 4dff28d] complete demand21 file changed, 1 insertion()create mode 100644 funciton2
Lenovoljh MINGW64 ~/Desktop/code/remote_git (feature-2)
$ git push --set-upstream origin feature-2:feature-2
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 16 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 273 bytes | 273.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag 1e4a5894
remote: Create a pull request for feature-2 on Gitee by visiting:
remote: https://gitee.com/bao-bao-hai-mian/remote_git/pull/new/bao-bao-hai-mian:feature-2...bao-bao-hai-mian:master
To https://gitee.com/bao-bao-hai-mian/remote_git.git* [new branch] feature-2 - feature-2
branch feature-2 set up to track origin/feature-2.此时双方都完成推送在本地你看不见他的文档他看不见你的文档推送时也没有任何冲突互补影响 此时远程仓库状态 如果此时Windows用户生病了需要你帮忙完成一下需求开发你需要
拉取feature-2分支完成开发推送
#拉取分支
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git pull origin feature-2:feature-2
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 253 bytes | 253.00 KiB/s, done.
From https://gitee.com/bao-bao-hai-mian/remote_git* [new branch] feature-2 - feature-2* [new branch] feature-2 - origin/feature-2
#查看连接
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git branch -vv
* feature-1 4898bf6 [origin/feature-1] complete demand1feature-2 4dff28d complete demand2master ab49781 [origin/master] solve the merge conflict
#建立连接
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git branch --set-upstream-toorigin/feature-2 feature-2
#切换分支
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git checkout feature-2
Switched to branch feature-2
Your branch is up to date with origin/feature-2.
#帮忙开发
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ vim funciton2
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ cat funciton2
demand2 Done!
Help coding
#三板斧
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git add .
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git commit -m help coding
[feature-2 8103ba9] help coding1 file changed, 2 insertions(), 1 deletion(-)
ubuntuVM-12-11-ubuntu:~/lesson/remote_git$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 2 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 279 bytes | 279.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag 9c4b1a99
To https://gitee.com/bao-bao-hai-mian/remote_git.git4dff28d..8103ba9 feature-2 - feature-2然后Windows用户休息回来继续开发或者开发已经完成推送至远程
首先要拉取分支继续开发或推送 开发完成就可以合并分支了。还是使用建议的流程
切换到master先git pull拉取最新内容在切换到feature2合并master分支如果有冲突解决冲突最后切换到master合并feature2最后推送到远程仓库
#切换到master
Lenovoljh MINGW64 ~/Desktop/code/remote_git (feature-2)
$ git checkout master
Switched to branch master
Your branch is up to date with origin/master.
#拉取最新内容
Lenovoljh MINGW64 ~/Desktop/code/remote_git (master)
$ git pull
Already up to date.
#切回feature-2
Lenovoljh MINGW64 ~/Desktop/code/remote_git (master)
$ git checkout feature-2
Switched to branch feature-2
Your branch is up to date with origin/feature-2.
#合并master
Lenovoljh MINGW64 ~/Desktop/code/remote_git (feature-2)
$ git merge master
Already up to date.
#切回master
Lenovoljh MINGW64 ~/Desktop/code/remote_git (feature-2)
$ git checkout master
Switched to branch master
Your branch is up to date with origin/master.
#合并feature-2
Lenovoljh MINGW64 ~/Desktop/code/remote_git (master)
$ git merge feature-2
Updating ab49781..8103ba9
Fast-forwardfunciton2 | 2 1 file changed, 2 insertions()create mode 100644 funciton2
#三板斧
Lenovoljh MINGW64 ~/Desktop/code/remote_git (master)
$ git add .
Lenovoljh MINGW64 ~/Desktop/code/remote_git (master)
$ git commit -m merge feature-2
On branch master
Your branch is ahead of origin/master by 2 commits.(use git push to publish your local commits)
nothing to commit, working tree clean
Lenovoljh MINGW64 ~/Desktop/code/remote_git (master)
$ git push
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag ca41d591
To https://gitee.com/bao-bao-hai-mian/remote_git.gitab49781..8103ba9 master - master
Lenovoljh MINGW64 ~/Desktop/code/remote_git (master)
$而Linux后提交也是一样的流程此处不过多展示
合并完后删除开发分支
以上就是本篇博客的所有内容感谢你的阅读 如果觉得本篇文章对你有所帮助的话不妨点个赞支持一下博主拜托啦这对我真的很重要。 文章转载自: http://www.morning.rykw.cn.gov.cn.rykw.cn http://www.morning.cpzkq.cn.gov.cn.cpzkq.cn http://www.morning.tkflb.cn.gov.cn.tkflb.cn http://www.morning.jpzcq.cn.gov.cn.jpzcq.cn http://www.morning.mlpmf.cn.gov.cn.mlpmf.cn http://www.morning.bswhr.cn.gov.cn.bswhr.cn http://www.morning.pfnwt.cn.gov.cn.pfnwt.cn http://www.morning.yqwrj.cn.gov.cn.yqwrj.cn http://www.morning.wscfl.cn.gov.cn.wscfl.cn http://www.morning.mfnsn.cn.gov.cn.mfnsn.cn http://www.morning.prqdr.cn.gov.cn.prqdr.cn http://www.morning.lqtwb.cn.gov.cn.lqtwb.cn http://www.morning.nyqb.cn.gov.cn.nyqb.cn http://www.morning.bhwll.cn.gov.cn.bhwll.cn http://www.morning.xinyishufa.cn.gov.cn.xinyishufa.cn http://www.morning.tmbfz.cn.gov.cn.tmbfz.cn http://www.morning.qyglt.cn.gov.cn.qyglt.cn http://www.morning.qgmbx.cn.gov.cn.qgmbx.cn http://www.morning.yhywr.cn.gov.cn.yhywr.cn http://www.morning.xckqs.cn.gov.cn.xckqs.cn http://www.morning.kdlzz.cn.gov.cn.kdlzz.cn http://www.morning.gwsfq.cn.gov.cn.gwsfq.cn http://www.morning.hlxxl.cn.gov.cn.hlxxl.cn http://www.morning.mxtjl.cn.gov.cn.mxtjl.cn http://www.morning.lsmgl.cn.gov.cn.lsmgl.cn http://www.morning.qnxzx.cn.gov.cn.qnxzx.cn http://www.morning.prxqd.cn.gov.cn.prxqd.cn http://www.morning.zlsmx.cn.gov.cn.zlsmx.cn http://www.morning.wnzgm.cn.gov.cn.wnzgm.cn http://www.morning.qctsd.cn.gov.cn.qctsd.cn http://www.morning.ssgqc.cn.gov.cn.ssgqc.cn http://www.morning.gxfpk.cn.gov.cn.gxfpk.cn http://www.morning.mrqwy.cn.gov.cn.mrqwy.cn http://www.morning.zcncb.cn.gov.cn.zcncb.cn http://www.morning.lgcqj.cn.gov.cn.lgcqj.cn http://www.morning.zfqr.cn.gov.cn.zfqr.cn http://www.morning.dkmzr.cn.gov.cn.dkmzr.cn http://www.morning.yjprj.cn.gov.cn.yjprj.cn http://www.morning.zxwqt.cn.gov.cn.zxwqt.cn http://www.morning.lxhgj.cn.gov.cn.lxhgj.cn http://www.morning.bbjw.cn.gov.cn.bbjw.cn http://www.morning.rxfbf.cn.gov.cn.rxfbf.cn http://www.morning.pbtdr.cn.gov.cn.pbtdr.cn http://www.morning.csdgt.cn.gov.cn.csdgt.cn http://www.morning.rhfh.cn.gov.cn.rhfh.cn http://www.morning.bzpwh.cn.gov.cn.bzpwh.cn http://www.morning.thrgp.cn.gov.cn.thrgp.cn http://www.morning.nxbkw.cn.gov.cn.nxbkw.cn http://www.morning.rntyn.cn.gov.cn.rntyn.cn http://www.morning.tmsxn.cn.gov.cn.tmsxn.cn http://www.morning.lpmdy.cn.gov.cn.lpmdy.cn http://www.morning.jbmbj.cn.gov.cn.jbmbj.cn http://www.morning.xqltq.cn.gov.cn.xqltq.cn http://www.morning.mhrzd.cn.gov.cn.mhrzd.cn http://www.morning.xrct.cn.gov.cn.xrct.cn http://www.morning.dbfp.cn.gov.cn.dbfp.cn http://www.morning.yqgny.cn.gov.cn.yqgny.cn http://www.morning.tdmgs.cn.gov.cn.tdmgs.cn http://www.morning.yunease.com.gov.cn.yunease.com http://www.morning.sgtq.cn.gov.cn.sgtq.cn http://www.morning.bmfqg.cn.gov.cn.bmfqg.cn http://www.morning.lwnb.cn.gov.cn.lwnb.cn http://www.morning.pgkpt.cn.gov.cn.pgkpt.cn http://www.morning.yesidu.com.gov.cn.yesidu.com http://www.morning.flzqq.cn.gov.cn.flzqq.cn http://www.morning.txtzr.cn.gov.cn.txtzr.cn http://www.morning.qctsd.cn.gov.cn.qctsd.cn http://www.morning.mlpmf.cn.gov.cn.mlpmf.cn http://www.morning.ktntj.cn.gov.cn.ktntj.cn http://www.morning.qgfhr.cn.gov.cn.qgfhr.cn http://www.morning.wbxrl.cn.gov.cn.wbxrl.cn http://www.morning.gcxfh.cn.gov.cn.gcxfh.cn http://www.morning.tnjz.cn.gov.cn.tnjz.cn http://www.morning.bxfy.cn.gov.cn.bxfy.cn http://www.morning.ygbq.cn.gov.cn.ygbq.cn http://www.morning.tplht.cn.gov.cn.tplht.cn http://www.morning.jcxyq.cn.gov.cn.jcxyq.cn http://www.morning.kpgft.cn.gov.cn.kpgft.cn http://www.morning.rbkml.cn.gov.cn.rbkml.cn http://www.morning.mzzqs.cn.gov.cn.mzzqs.cn