初学Git -- 本地文件通过git上传至github(小结)

前言

  • 记录时间:2020.3.19
  • 记录内容:如何将本地文件通过git上传至github(主讲如何上传)
    • 一、前期准备
    • 二、第一次上传
    • 三、第二次上传
    • 四、后记的话

一、前期准备

  1. 进入GitHub官网 --> 注册个人账户 --> 创建空仓库
  2. 进入Git官网 --> 下载git

二、第一次上传

具体可看:[初学Git - 将本地文件传至Github]

Step1:右键需要上传的文件 --> 右键任意空白处 --> 选择 Git Bash Here

  • 本步骤可代替下方黑框输入的cd。
  • 需要注意的是:
    假设是在A文件夹下进行该操作,那么上传的将是A文件下的子文件,而非单纯整个像压缩包一样的A文件。
    在这里插入图片描述

Step2:在黑框中依次输入下方代码

  • 需要注意的是:
    中午字部分是要更改的
cd
git init
git config user.name "用户名"
git config user.email "邮箱" 
git add *
git commit -m "备注"
git remote add origin https://github.com/GitHub用户名/仓库名.git
git push -u origin master

三、第二次上传

Step1:将目标仓库中的所有文件加载到本地上传的A文件中

  • 出现下方报错:

Another git process semms to be running in this repository, e.g. an editor opened by ‘git commit’. Please make sure all processes are terminated then try again. If it still fails, a git process remove the file manually to continue…

  • 本操作主要是由于本地A文件内部的子文件已发生删除或者改名等其他的更改,导致与第一次上传到的GitHub目标仓库内容不一致了,即“GitHub中存在,但本地A文件中不存在”。如果此状态下去上传,那么git就搞不清你要怎么处理那些github中存在但是本地A文件中不存在的东西了,于是就会导致上传失败。

git pull origin master
git push -u origin master

Step2:重新按照第一次上传的方式上传即可

Step3:关于隐藏文件的问题

  • 出现下方报错:

Another git process semms to be running in this repository, e.g. an editor opened by ‘git commit’. Please make sure all processes are terminated then try again. If it still fails, a git process remove the file manually to continue…

  • 大概意思是git被另外一个程序占用,重启机器也不能够解决。原因在于Git在使用过程中遭遇了奔溃,部分被上锁资源没有被释放导致的。

进入项目文件夹下的 .git文件中(显示隐藏文件夹或rm .git/index.lock)
删除index.lock文件即可。

四、后记的话

文件中(显示隐藏文件夹或rm .git/index.lock)

删除index.lock文件即可。

四、后记的话

  • 本篇算是前几篇“初学git”的一个总结提炼。。。基本上都CV过来了。。。后期查问题和使用可以直接看这一篇。
发布了19 篇原创文章 · 获赞 0 · 访问量 1997

猜你喜欢

转载自blog.csdn.net/hyidol/article/details/104974612
今日推荐