文章是copy来的.但当时一直没成功.第5步之后有我补充内容.能帮到您是我的荣幸
准备工作:
在github/gitlab中新建项目audit
1.在本地目录zhunions目录下初始化本地仓库
git init
2.建立.gitignore README.md文件
3.本地提交
git add .
git commit -m "first commit"
4.添加远程关联
git remote add origin git@172.16.10.9:namespace/zhunions.git
5.本地分支与远程分支关联,并推送到远程仓库
git push --set-upstream origin master
以上5步可以完成本地仓库和分支与远程仓库和分支的关联.
如果出现 git pull 出现
warning: no common commits
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)
Unpacking objects: 100% (4/4), done.
From https://gitee.com/qbz2004/enter_manager
* [new branch] master -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
执行
git branch --set-upstream-to=origin/master
master
或者出现
fatal: refusing to merge unrelated histories
执行
git pull origin branchname --allow-unrelated-histories
branchname 改成 master
本地 master 与 远程master已经建立好关联
下一步切换到dev上
$ git branch -a
* master
remotes/origin/dev
remotes/origin/master
切换分支
git branch --set-upstream-to=origin/dev dev
未完待续
执行所有操作后,有如下结果:
a.产生本地分支master
b.与本地仓库关联的远程仓库origin
c.与本地分支关联的远程分支master
d.本地代码全部提交到了远程仓库,其他人可以共享了