1、登录git账户,新建一个代码仓库
2、将本地和远程厂库关联起来
git remote add origin git@github:地址/远程项目名称.git
3、将本地代码推送到库上
git add .
git commit -m ‘first’ -n
git push -u origin master
可能出现的问题如下:
问题1.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
解决方法:
使用ssh key这种方式进行clone ,pull github上面的项目,使用 git clone或者git pull origin master出现permission denied (publickey),原因是因为ssh key过期失效或者没有ssh key。 那么解决这种的问题的方法就是重新生成一个新的ssh key ,然后将这个ssh key添加到github账户上面,就可以了。
用这个命令
ls ~/.ssh/
进行检查 id_rsa.pub 是否存在,如果存在,就不用生成一个新的SSH key了,直接跳到下面的第3步。
先:
cd /Users/your_user_name/.ssh
命令如下:
ssh-keygen -t rsa -b 2048 -C “your_email@example”
其中,your_email@example
要修改成你的邮箱地址。
回车后输出如下:
Generating public/private rsa key pair. Enter file in which to save the key (/Users/your_user_name/.ssh/id_rsa):
直接回车,会将key保存到默认文件中。
接着会输出:
Enter passphrase (empty for no passphrase): Enter same passphrase again:
这两步是让你输入一个密码,以及确认密码,这个密码在你提交代码到Github时会用到【注意:记住这个密码,最简单的方式就是设置的和github账户登入密码一样,容易记住】
回车后就提示成功了:
Your identification has been saved in /Users/your_user_name/.ssh/id_rsa. Your public key has been saved in /Users/your_user_name/.ssh/id_rsa.pub. The key fingerprint is: 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example
到这一步,你会发现 /Users/your_user_name/.ssh/id_rsa.pub
文件已经生成了。
打开id_rsa.pub
文件,复制里面的内容,然后粘贴到git中相关的位置中。
例如对于gitlab 来说:
问题2.
! [rejected] master -> master (non-fast-forward)
error: 无法推送一些引用到 ‘git@github:fjydpf/ECUControl.git’
提示:更新被拒绝,因为您当前分支的最新提交落后于其对应的远程分支。
提示:再次推送前,先与远程变更合并(如 ‘git pull …’)。详见
提示:‘git push --help’ 中的 ‘Note about fast-forwards’ 小节。
解决方法:
$git fetch origin //获取远程更新
$git merge origin/master //把更新的内容合并到本地分支
问题3:
$ git merge origin/master
fatal: refusing to merge unrelated histories
解决方法:
使用这个强制的方法
git pull origin master --allow-unrelated-histories
后面加上 --allow-unrelated-histories , 把两段不相干的 分支进行强行合并
然后再执行git push -u origin master
本文发布于:2024-02-01 23:48:27,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170680751239961.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |