目录
在码云或者git上创建本地仓库
填写相关信息即可创建。
复制git或者码云上的地址
在本地项目文件夹下打开git bash
在窗口中执行:
git init 初始化
git remote add origin https://gitee.com/CoderJu/Java8.git(刚刚复制的地址)
git push -u origin master
可能会出现以下错误:
1. 出现错误
error:src refspec master does not match any
执行以下代码解决错误:
touch README
git add README
git commit –m ’first commit’
git push origin master
再执行:
git remote add origin https://gitee.com/CoderJu/Java8.git(刚刚复制的地址)
git push -u origin master
2. 这时候有可能会出现以下错误
fatal: remote origin already exists.
执行一下语句解决错误:
git remote rm origin
3. 也有可能出现以下错误
$ git push origin master
To https://gitee.com/CoderJu/Java8.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/CoderJu/Java8.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 pull --rebase origin master
4. 错误
error: Could not remove config section 'remote.origin'
需要修改gitconfig文件的内容 找到github的安装路径,我是C:\Users\Administrator\AppData\Local\GitHub\PortableGit_0f65d050d0c352找到一个名为gitconfig的文件,打开它把
里面的[remote "origin"]那一行删掉重启gitshell 执行上述操作。
项目集成功
另一种方式关联项目
在github或者码云上创建仓库后 复制仓库地址 比如 https://github.com/lujianing/demo.git在intellij中 VCS——Checkout from Version Contrl——Git中 粘贴仓库url地址会从github仓库中拷贝一份项目 然后就可以在本地直接进行git操作并且可以push到github仓库中 (会提示你输入github的仓库和密码)