将别人在Gitee上的代码更新到自己的项目中
如果你想将别人在Gitee上的代码更新到自己的项目中,可以按照以下步骤进行操作:
1. Fork别人的代码仓库: 在别人的代码仓库页面,点击右上角的" Fork"按钮。这将会将别人的代码仓库复制到你自己的账号下,创建一个新的项目。
2. Clone你自己的项目: 在你的账号下找到刚刚Fork的项目,点击" Clone or Download"按钮,获取项目的URL。然后在本地使用git命令克隆项目到你的计算机上。
bashCopy code
git clone <your-forked-repo-url>
//如我的
git clone https://gitee.com/xxx/vue3-element-admin.git
3. 添加源仓库(别人的代码仓库): 进入你刚刚克隆的项目目录,并添加源仓库(别人的代码仓库)作为远程仓库。
不要忘了切换路径后再配置,我之前用的一直值克隆项目的父目录,导致一直有问题!!!!
bashCopy code
git remote add upstream <original-repo-url>
//如:
git remote add upstream https://gitee.com/youlaiorg/vue3-element-admin.git
这样你就可以用upstream这个名称代指别人的代码仓库。
***********一般不会出错,除非刚才没有切换路径。–开始
注:如有报错: fatal: not a git repository (or any of the parent directories): .git
运行下行代码即可
git init
***********无错不需要再看–结束
4. 拉取源仓库的更新: 在你本地的项目目录下,首先切换到main(或者master,根据仓库默认分支的名称来决定)分支,确保你在主分支上进行操作。我自己的为master
bashCopy code
git checkout master
//如果已经是了,不用再执行
然后拉取源仓库的更新到本地。
bashCopy code
git pull upstream master
这将会将别人代码仓库中main分支的最新代码拉取到你本地的主分支。
5. 推送更新到你的项目: 最后,将本地的更新推送到你自己的项目中。
bashCopy code
git push origin master
这样,你的项目就会包含了别人代码仓库的最新更新。
每当你想获取别人代码仓库的新更新时,只需要重复第4和第5步即可。记住,这里假设使用main作为主分支名称,如果实际情况中使用了其他名称,请根据实际情况进行相应的调整
***********以下无错不需要再看–开始
一般不会出错,除非刚才没有切换路径。
注意:如果有以下报错
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
解决: 运行git remote -v ,显示如下,无origin
$ git remote -v
upstream https://gitee.com/youlaiorg/vue3-element-admin.git (fetch)
upstream https://gitee.com/youlaiorg/vue3-element-admin.git (push)
所以再次自定义了origin为自己的仓库名称;upstream为别人的仓库名称(上面已操作)
git remote add origin https://gitee.com/xxx/vue3-element-admin.git
再运行代码即可
git push origin master
***********无错不需要再看此内容–结束
另外:
git push origin master 后是这样的页面,填入自己的git信息即可
输入后如果报以下错:
$ git push origin master
remote: [session-6841d990] xxx: Incorrect username or password (access token)
fatal: Authentication failed for 'https://gitee.com/xxx/vue3-element-admin.git/'
重置账号,密码即可:
git config --system --unset credential.helper
这样再次提交后可以重新输入账号密码,另外,谨记:账号是注册的邮箱!!!!,试了好多遍才知道。
知识点1:
查看分支:git branch
切换分支:git checkout master
再次查看分支:git branch
知识点2:
来源:https://www.zhihu.com/question/615025469/answer/3148699944