GitHub创建仓库

 

0.本地安装Git

git如何上传本地文件到github仓库(超详细教程)_stc的博客-CSDN博客_git上传文件到github仓库

如何将本地项目上传到Github_weixin_30246221的博客-CSDN博客

1 本地电脑和GitHub建立链接:

直接跳到第三步,

使用下面命令更加方便:

ssh-keygen -t rsa -C "478377515@qq.com"
【enter】
cd ~
ls -al
cd .ssh/
cat id_rsa.pub

打开id_rsa.pub中文件之后,复制

之后进行第四步操作

验证:ssh -T git@github.com

2. 创建新仓库

记得之后需要复制的链接为SSH中的,不是HTTPS.

3. 上传:

使用git打开需要上传的文件夹 Git Bash Here
git init
git add . #git add xxx //xxx为文件或目录名(比如git add /home/xumin/test)
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:XuminGaoGithub/MMUU-Net.git #(github.com:XuminGaoGithub/MMUU-Net.git替换成对应的)
git push -u origin main





------使用下面的master方式不行,还是使用上面的------

git add .
#如果像我一样需要添加文件夹,输入
git add /home/xj/UCB_pacman/search0103
#后面为需要的文件夹路径
 
#上传文件至本地仓库, -m之后的输入是本次提交的说明。
git commit -m "first commite"        
 
#将本地文件夹和github仓库关联,后面是自己之前新建的github仓库地址
git remote add origin git@github.com:XieJia15/UCB-pacman-AI-projects.git
 
#输入用户名和密码,输入正确,就可以成功将README.md上传到github上。
git push origin master
-----------------------------------

4.界面显示图片

在README.md中填入:

![Image text](https://raw.github.com/yourName/repositpry/master/yourprojectName/img-folder/test.jpg) ###代替为你的图片的路径

保存即可。

其他参考:

Ubuntu中安装git并push本地文件到github操作步骤_JL_liushengjie的博客-CSDN博客

Ubuntu18.04上传文件夹到github - 灰信网(软件开发博客聚合)

5. github里如何删除一个repository仓库:

github里如何删除一个repository仓库 - lizhenghn - 博客园

6. fatal: remote origin already exists. (远程来源已经存在 解决办法)

在当我们输入` git remote add origin https://gitee.com/(github/码云账号)/(github/码云项目名).git `

就会报如下的错

fatal: remote origin already exists.  

翻译过来就是:致命:远程来源已经存在

此时,我们可以先 git remote -v 查看远程库信息:

可以看到,本地库已经关联了origin的远程库,并且,该远程库指向GitHub。

解决办法如下:

1、先输入$ git remote rm origin(删除关联的origin的远程库)

2、再输入$ git remote add origin git@github.com:(github名)/(git项目名).git 就不会报错了!

3、如果输入$ git remote rm origin 还是报错的话,error: Could not remove config section 'remote.origin'. 我们需要修改gitconfig文件的内容

4、找到你的github的安装路径,我的是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc

5、找到一个名为gitconfig的文件,打开它把里面的[remote "origin"]那一行删掉就好了!

记一次我关联远程库遇到的错误

用了上面的办法我就解决了(  希望能对看到的人有所帮助 )

推荐npm全局安装和本地安装及卸载
————————————————
版权声明:本文为CSDN博主「码知秋」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_40428678/article/details/84074207

7. 如果包含其他作者的包,报错

warning: adding embedded git repository: test
hint: You’ve added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:

解决方法:

找到对应包,ctrl+h,删除。.git文件下的文件或.git文件。

8.如果有.gitignore文件,对应的文件会被忽略导致不上传,删除即可

9.github this exceeds GitHub‘s file size limit of 100.00 MB解决办法

ctrl+h,显示隐藏的文件。删除.git相关的文件。重新打开terminal,重新上传。

sudo apt-get install git-lfs

xumin@xumin-lenovo-legion-y7000p-1060:~$ cd test2

xumin@xumin-lenovo-legion-y7000p-1060:~/test2$ git init
Initialised empty Git repository in /home/xumin/test2/.git/

xumin@xumin-lenovo-legion-y7000p-1060:~/test2$ git lfs install


Updated git hooks.
Git LFS initialized.

xumin@xumin-lenovo-legion-y7000p-1060:~/test2$ find ./ -size +100M
./darknet_ros/darknet_ros/yolo_network_config/weights/my_yolov3_14000.weights

xumin@xumin-lenovo-legion-y7000p-1060:~/test2$ git lfs track "my_yolov3_14000.weights"

Tracking "my_yolov3_14000.weights"

or xumin@xumin-lenovo-legion-y7000p-1060:~/test2$ git lfs track "xxx_dir/*" #(所有文件)

Tracking "aphid_counting/*"

xumin@xumin-lenovo-legion-y7000p-1060:~/test2$ git add .

xumin@xumin-lenovo-legion-y7000p-1060:~/test2$ git commit -m "first commit"

xumin@xumin-lenovo-legion-y7000p-1060:~/test2$ git remote add origin git@github.com:XuminGaoGithub/tt.git


xumin@xumin-lenovo-legion-y7000p-1060:~/test2$ git push -u origin main

10. Git常见错误与操作:error: src refspec master does not match any解决办法

一、 出现错误 error:src refspec master does not match any

原因分析:

引起该错误的原因是目录中没有文件,空目录是不能提交上去的

解决办法:

$ touch README
$ git add README
$ git commit -m "first commit"
$ git push origin main #master

11. git:重命名本地分支失败

git:重命名本地分支失败 | 那些遇到过的问题

error: refname refs/heads/HEAD not found fatal: Branch rename failed

通过以下命令添加我的第一个提交后,一切正常。

git add .
git commit -m 'Init'

参考:

github this exceeds GitHub‘s file size limit of 100.00 MB解决办法_小明的专栏-CSDN博客

关于github不给上传100m以上文件的错误:this exceeds GitHub's file size limit of 100.00 MB的解决方法_Jason Zhou-CSDN博客

10.

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.

解决方法:

(1)git pull #先执行pull

(2)首先运行拉取命令 git pull --rebase origin main #or master

最后再执行推送命令 git push -u origin main #or master

(3) 如果(1)(2)都不生效,则用(3):

git push -f origin main #or master

***如果respo 为master 而非main, 则对应修改为git push -f origin master

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值