本地项目如何连接git远程仓库

在本地新建项目后,如何连接git远程仓库呢?步骤如下:

第一步, 首先我们在git上新建仓库,设置模板可勾选Readme文件。(readme文件的创建是为了介绍所写代码的一些详细信息,为了之后更好的维护。)

在这里插入图片描述

第二步,打开本地项目文件夹,鼠标右键选择Git Bash Here 。

在这里插入图片描述

第三步,输入git init 命令(在目录中创建新的 Git 仓库)

在这里插入图片描述

第四步,输入完git init之后,可以看到在项目中自动生成了.git子目录文件,这就是你的git仓库了,所有有关你的此项目的快照数据都存放在这里。

在这里插入图片描述

第五步,复制git仓库项目链接,在命令窗口输入 git remote add origin ‘项目地址’,这个时候本地项目就和git远程仓库建立起连接了。

在这里插入图片描述

在这里插入图片描述

第六步,输入 git pull origin master ;把git上的文件拉取下来。(勾选了Readme生成的文件)

在这里插入图片描述

第七步,输入 git add . ( 添加本地项目中的所有文件到暂存区)

在这里插入图片描述

第八步,输入 git commit -m “提交信息” ( 提交暂存区到本地仓库中 )

在这里插入图片描述

第九步,输入git push origin master (将本地的 master 分支推送到 origin 主机的 master 分支。)

在这里插入图片描述

在这里插入图片描述

由此,就完成了本地项目仓库和git远程仓库的连接,后续就可以实现从git上拉取项目或从本地推送项目到git仓库了。


后续提示:

更新项目出现There is no tracking information for the current branch. Please specify which branch you want to merge with. 怎么解决

原因: 是因为本地的分支和远程的没有建立关联导致的
当出现上面的情况时,我们可以有两种解决方法
解决方法:
1.直接指定远程master

git pull origin master

2.先指定本地master到远程的master,然后再去pull

git branch --set-upstream-to=origin/远程分支名 本地分支名
即:git branch --set-upstream-to=origin/master master

再通过 git branch -vv 确认是否关联成功。

这样就不会再出现“There is no tracking information for the current branch”这样的提示了。

猜你喜欢

转载自blog.csdn.net/chb19991118/article/details/132163914