GitHub仓库操作

一、基础操作,本地上传GitHub

1、在GitHub上新建仓库 此时只有一个分支master分支

在这里插入图片描述
在这里插入图片描述

2、在本地下载这个仓库

$ git clone https://github.com/fanghejun/crawler.git

3、在本地仓库放入新建的文件和文件夹,上传到GitHub

$ cd git_first/ # 进入到工程文件
$ git add . # 将修改的文件夹和文件加载到本地待上传区
$ git commit  -m  "first commit" # 本次上传的注释
$ git push origin master

二、分支操作

1、创建分支并上传数据

(master)$ git branch test_branch     # 创建另一个分支                                                                                            
(master)$ git checkout test_branch # 切换分支
(test_branch)$ git remote add origin https://github.com/zjq7/stoke-DeepRL.git  
# 与远程分支关联, 但是这里已经在GitHub上建立, 无需二次建立   ,因此这里可能会报错                                                   
(test_branch)$ git add .                                                                                                             
(test_branch)$ git commit  -m  "branch test first"
(test_branch)$ git push -u origin test_branch

三、合并分支到主分支

(test_branch)$ git checkout master         # 从test_branch分支切换到主分支                                                                                           
(master)$ git merge test_branch        # 合并分支到主分支      
(master) $ git push # 将分支数据合并到到master
To https://github.com/FrancisWangH/NISL_EUROSYS2021.git
! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/FrancisWangH/NISL_EUROSYS2021.git'
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.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
上面的错误可以通过
$ git pull origin master # 以为我们在GitHub上修改文件后, 与本地就不同步了, 因此会报错
$ git push # 这里重新push就好了
Everything up-to-date

四、问题总结

1、GitHub上修改了文件,本地也修改了,直接可以下载GitHub的文件。
2、本地GitHub项目上传到gitee

先在gitee上创建一个新的项目, 如test.然后得到test的git链接
$ https://gitee.com/fhj/test.git
然后在本地下载GitHub的项目
$ git clone --recursive https://github.com/fhj/crawler
在删除本地GitHub项目与远程GitHub的联系
$ git remote rm origin
本地项目与远程gitee进行链接
$ git remote add origin https://gitee.com/fhj/test.git
在将本地项目上传到gitee
$ git push --set-upstream origin main

3、删除当前项目的远程连接,建立新的连接

$ git remote rm origin // 移除本地关联
$ git remote add origin git@**.git // 添加线上仓库
$ git push -u origin master // 注意:更改后,第一次上传需要指定 origin

4、一直显示GitHub连接失败

$ git config --global  --unset https.https://github.com.proxy
$ git config --global  --unset http.https://github.com.proxy

5、更换版本

$ git tag # 查看都有那些版本
$ git checkout v1.6.0 # 根据上面提示, 更换版本

6、

# 具体错误
git clone https://github.com/jqzhao7/scan.git
Cloning into 'scan'...
fatal: unable to access 'https://github.com/jqzhao7/scan.git/': Failed to connect to github.com port 443: Connection refused

# 下面两个命令执行后就能解决上述问题
$ git config --global http.proxy http://127.0.0.1:1080
$ git config --global https.proxy http://127.0.0.1:1080
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值