DongboShi / bigdata_econ

This project contains the tutorials of the course 'big data for economics research'
11 stars 24 forks source link

实现git push的辛酸历程及关于SSH、提示需要输入密码和You are not currently on a branch的解决办法 #4

Closed linyanbruce closed 10 months ago

linyanbruce commented 10 months ago

git push 中间遇到的几个问题

SSH钥匙配置受阻

老老实实按教程注册,挡住我最多的其实是找不到GitHub界面上的入口( 在使用ssh-keygen -t rsa之后返回

Generating public/private rsa key pair.
Enter file in which to save the key (/home/debian/.ssh/id_rsa)

还有一个是./ssh 这个存放钥匙的文件夹好像是隐藏的 所以cd一下定位,然后通过cat命令读取内容,粘贴回github上的ssh key,其他阻力好像没有什么了,欢迎大家补充

git push -u origin master 时需要输入账户与密码

参考的是BSY丶的帖子 返回的时候提示的是

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/username/repository.git/'

这个问题的原因:github的认证策略发生了改变,在 2021年8月13日 的时候,用户名加密码的认证方式被去掉了,换成了 个人令牌(Personal Access Token)的校验方式。 解决过程中经过了两个步骤

第一步则是靠设置token的方式登录

b42073661b0040588081bebf1addfba7

其中过期时间设置了60天,主要怕我之后忘记怎么做,权限按需选择,也可以全选,生成之后填写命名,这个用来填入下方的 键入 git remote set-url origin https://<token>@github.com/username/repository.git 之后再键入 git push origin master 就没问题了,输入password(这里我忘记了是账号密码还是回车,欢迎补充,)

第二步个是靠把http的方式改为了ssh的格式

先键入git remote -v,返回如下: origin https://github.com/username/repository.git (fetch) origin https://github.com/username/repository.git (push) 键入 git remote rm origin,再次查询就是空的了 输入 git remote add origin git@github.com/username/repository.git,将http更改为ssh的格式, 然后使用 git push -u origin master,就能看到仓库里出现文件了。

问题3 You are not currently on a branch

参照的是高低捣蛋鬼的教程

首先是报错信息

You are not currently on a branch, so I cannot use any
'branch.<branchname>.merge' in your configuration file.
Please specify which remote branch you want to use on the command
line and try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push origin HEAD:<name-of-remote-branch>

(因为我把Debian关了,报错信息没法用一手,就粘贴了大佬的教程),

一手 git branch,看看自己在哪,返回:

git branch
* (HEAD detached from bdcfe3d8)
* master
* issue68

执行如下操作:

git branch temp bdcfe3d8
git checkout master
git merge temp

就是创建分支——切换回master分支——将分支temp合并到master 然后就可以使用git pullgit push了 最后(我是在pull之前),删除temp分支 git branch -d temp 搞定 其他的有点忘记了,习惯不是很好,下次我及时写文档里保存、、、

linyanbruce commented 10 months ago

噢原来是自己提问啊 我是解决了才来的 笑晕

DongboShi commented 10 months ago

感谢你详细的解决方案