1、初始化仓库
git init
2、 添加文件到本地仓库
git add .(文件name)
3、添加文件描述信息
git commit -m "first commit"
4、链接远程仓库,创建主分支
git remote add origin + 远程仓库地址
5、把本地仓库的变化连接到远程仓库主分支
git pull origin master
这一步如果报错:refusing to merge unrelated histories
(1) 执行:
git pull origin master --allow-unrelated-histories
或 git pull --allow-unrelated-histories
如果报错:
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>
说明本地分支和远程分支没有建立联系,执行下面命令来建立联系
git branch --set-upstream-to=origin/远程分支的名字 本地分支的名字
(2) 如果继续报错:
error: failed to push some refs to 'git@github.com:CNCFOX/NDKLearn.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
通过git status
查看提交过程:
此时Git处于mergeing的状态,在VScode中会标出冲突的部分,选择接受现有更改或者其他选择。完成后打开VScode中左边的git工具栏,接受已经做出的更改。
(3) 这些操作完成之后,重新执行git add .
(4) 然后执行git commit -s
(5) 再执行git pull origin master
6、将代码push到远程的仓库中
git push origin master
注:
如果在执行git clone时只clone了部分文件说明没有指定具体的分支
1.git clone 不指定分支
git clone http://10.1.1.11/service/sz-service.git
2.git clone 指定分支
git clone -b master http://10.1.1.11/service/sz-service.git
命令中:
多了一个-b master,这个master就是分支,http://10.1.1.11/service/sz-service.git为源码的仓库地址
网友评论