前提
Git仓库已经创建好用户并且配置好公钥,已经加入或者获取了项目的git地址。
建立本地GIT仓库
说明:
window系统下,GIT对系统盘默认挂载在根目录,即访问D盘直接使用/d,E盘则直接使用/e
远程仓库的地址需要根据项目情况进行配置
创建本地文件夹
根据个人情况创建。下为示例,
该文件夹用来存放项目的代码,即本地git仓库的物理地址。
在D盘建立文件夹:git_repository,之后依次建立:csvalue/product/asc/usc ups
进入创建好的目录
打开之前安装好的Git Bash,输入
cd /d
之后参照上图,使用命令依次进行创建好的文件夹(上图使用命令行方式创建了文件夹,直接使用window命令创建也可以)
一直进入到asc文件夹
仓库相关操作
以上个章节独立,根据需要独自参考进行操作。
如果是关联现有代码,建议将现有代码复制到上一步创建的仓库目录,再按照执行操作进行创建
下载代码
直接在项目仓库目录下执行:
整体下载:
- 这种方式会在asc下创建一个usc的项目目录,项目代码在usc目录(git配置文件在asc目录内)
cd asc
git clone http://139.196.191.0:8555/asc/usc.git
- 这种方式在d:/git_repository/csvalue/product/asc/usc目录下载项目代码(git配置文件在usc目录内)
cd usc
git clone http://139.196.191.0:8555/asc/usc.git /d/git_repository/csvalue/product/asc/usc
上传代码
进入USC文件夹后,依次使用
git init
git remote add origin http://139.196.191.0:8555/asc/usc.git
git add .
git commit -m "Initial commit"
git push -u origin master
之后进入ups,建立ups的本地仓库
cd ..
cd ups
git init
git remote add origin http://139.196.191.0:8555/asc/ups.git
git add .
git commit -m "Initial commit"
git push -u origin master
更新代码
git pull
关联现有代码
如果项目代码已经存在,可以将git的代码与当前代码进行关联。
注意关联现有项目代码时,需要现有项目代码的文件夹名与git上的项目名完全一致
之后在进入项目所在的文件夹,执行
cd asc/ups
git init
git remote add origin http://139.196.191.0:8555/asc/ups.git
git add .
git commit -m "Initial commit"
git pull
如果最后一步git pull报如下错误信息:
$ git pull
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> dev
原因是没有指定本地dev分支与远程origin/dev分支的链接,根据提示,设置dev和origin/dev的链接。则按照提示执行
git branch --set-upstream-to=origin/master master
之后再执行git pull方法,有可能会报:refusing to merge unrelated histories错误,原因参见[[错误原因]][1]
则执行
git pull origin master --allow-unrelated-histories
如果提交(git push)报错,需要先git pull现在代码后,修改冲突再进行提交
相关项目地址
USC:http://139.196.191.0:8555/asc/usc.git
UPS:http://139.196.191.0:8555/asc/ups.git
USCAPP:http://139.196.191.0:8555/asc/uscApp.git