Github创建一个新仓库,关联本地数据并上传文件的图文步骤

工作中,我们经常会使用github来承享别人的代码果实,同时我们也会把自己的成果分享给别人,互相帮助。
今天的这篇图文教程非常重要,目标是使用Github来创建一个远程仓库,并和本地仓库对接,同时要做上传新内容到github仓库的任务。

假设我们已经拥有账户,并通过用户名密码登录到PC的页面上:https://github.com/

步骤1: 点击右上角的+号,创建新仓库

一个仓库包含所有项目文件,包括修订历史。

在这里插入图片描述

步骤2: 填写仓库名称和介绍

如图所示,在相应的位置,先写好标记信息,点击创建。

在这里插入图片描述

步骤3: 完成创建,获取git的url地址

通过上面创建好远程仓库,点击code的小三角,弹出url地址,这里复制 https://github.com/dajianshi/vue-cesium.git,留着下面的步骤使用。

在这里插入图片描述

步骤4: 进入本地工程,使用git init创建本地仓库

打开本地工程
在这里插入图片描述
调出Powershell或者cmd, 执行 git init

在这里插入图片描述

步骤5: 本地仓库对接远程仓库。

git remote add origin https://github.com/dajianshi/vue-cesium.git

步骤6: 添加文件、注释、本地换分支,上传远程仓库

添加文件: git add .

添加注释: git commit -m " init project"

更换本地仓库分支: git branch -M main

上传到远程仓库: git push -u -f origin main

注意:新建本地仓库默认为master分支,第3步要进行转换为main分支。

上传完后的效果:在这里插入图片描述

常见问题(1):git push时候的问题

(1)Git在push推送时,报错提示信息如下:

hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: ‘git pull …’) before pushing again.

原因分析
是由于本地和远程仓库两者代码文件不同步,因此需要先pull,进行合并然后再进行push

解决方法
1、先使用pull命令:

git pull --rebase origin main

2、再使用push命令:

git push -u origin main

常见问题(2):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
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/ release

原因分析
使用git在本地新建一个分支后,需要做远程分支关联。如果没有关联,git会在下面的操作中提示你显示的添加关联。

关联目的是在执行git pull, git push操作时就不需要指定对应的远程分支,你只要没有显示指定,git pull的时候,就会提示你。

解决方法

git branch --set-upstream-to=origin/remote_branch your_branch

其中,origin/remote_branch是你本地分支对应的远程分支;your_branch是你当前的本地分支。

猜你喜欢

转载自blog.csdn.net/cuclife/article/details/130369873
今日推荐