Git入门指令

Git入门指令

一、下载及查阅资料

Git下载

Git和码云使用参考资料

二、秘钥生成

1、****打开终端(git)进入.ssh目录


cd ~/.ssh 

如果没有,创建改文件夹

mkdir ~/.ssh

2、生成RSA秘钥


ssh-keygen -t rsa -C "你的邮箱@xxx.com"

3、查看秘钥并将秘钥部署到github


cat ~/.ssh/id_rsa.pub

三、GIt常用操作

1、克隆远程仓库代码,生成本地仓库:

代码格式:


git clone “git@ssh地址”

例如:


git clone git@gitee.com:github-29529984/mooc.git

下载存储在远程仓库git@gitee.com:github-29529984/mooc.git的代码

2、提交代码:

a、git add . =>有有变化的文件提交到缓冲区

b、git commit -m 'init' => 设置评论

c、git push origin master => 上传到master分支


\#  git add .

\#  git commit -m 'init'

\#  git push origin master

#将当前分支与远程分支融合,并存入缓冲区


\#  git pull origin master

3、新建组合操作

a、新建项目文件,进入


cd 项目名

b、建立git仓库


git init

c、将项目中新增或有变化的文件上传到缓冲区


git add .

d、将add的文件添加备注


git commit -m '备注'

e、将本地仓库关联到码云上


git remote add origin git@gitee.com:shiqingqing/test.git

f、上传码云前要先pull 下,把码云中的代码与本地代码融合


git pull origin  master

g、最后一步 上传代码到码云仓库


git push origin  master

四、可能问题

问题1:如何去解决fatal: refusing to merge unrelated histories

答:因为两个仓库不同,发现refusing to merge unrelated histories,无法pull

因为他们是两个不同的项目,要把两个不同的项目合并,git需要添加一句代码,在git pull,

这句代码是在git 2.9.2版本发生的,最新的版本需要添加--allow-unrelated-histories


git pull origin master --allow-unrelated-histories

参考:https://blog.csdn.net/m0_37402140/article/details/72801372

问题2: failed to push some refs to 'git@gitee.com:software_reliability/java_timeseries.git'

$ git push origin master

To gitee.com:software_reliability/java_timeseries.git

! [rejected] master -> master (non-fast-forward)

error: failed to push some refs to 'git@gitee.com:software_reliability/java_timeseries.git'

hint: Updates were rejected because the tip of your current branch is behind

hint: its remote counterpart. Integrate the remote changes (e.g.

hint: 'git pull ...') before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for details.

原因:

出现错误的主要原因是github中的README.md文件不在本地代码目录中

可以通过如下命令进行代码合并【注:pull=fetch+merge]


git pull --rebase origin master

参考:https://jingyan.baidu.com/article/f3e34a12a25bc8f5ea65354a.html

问题3:git报错:'fatal:remote origin already exists'怎么处理?

步骤1:删除remote


git remote rm origin

步骤2:重新添加remote


git remote add origin git@ssh

问题4:删除git remote

迁移原文:https://blog.csdn.net/luodao_/article/details/79041918

删除****git remote

查看当前存在的远程连接remote


$git remote -v

---

origin https://github.com/luodao236/test.git (fetch)

origin https://github.com/luodao236/test.git (push)

test https://github.com/luodao236/onceAgain.git (fetch)

test https://github.com/luodao236/onceAgain.git (push)

---------------------

现在想删除其中的一个test,方法为:


git remote remove <name>

$ git remote remove test

结果为:

$ git remote -v

origin https://github.com/luodao236/test.git (fetch)

origin https://github.com/luodao236/test.git (push)

---------------------

问题5:ERROR: Repository not found.

$ git push -u origin master

ERROR: Repository not found.

fatal: Could not read from remote repository.

Please make sure you have the correct access rights

and the repository exists.

-----

解决,添加公有秘钥到项目中

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Git有很多优势,其中之一就是远程操作非常简便。本文详细介绍5个Git命令,它们的概念和用法,理解了这些内容,你就...
    bondPang阅读 5,158评论 0 6
  • Lesson 3: Using GitHub to Collaborate 3.1 Creating a GitH...
    赤乐君阅读 11,330评论 3 11
  • 转自:https://mp.weixin.qq.com/s/sF-cx2ss4haO74K55Sjf9g 配置 首...
    faremax阅读 2,286评论 0 0
  • 配置 首先是配置帐号信息ssh -T git@github.com # 登陆 github 修改项目中的个人信息 ...
    guanguans阅读 4,104评论 0 3
  • 喊故乡 作者:田禾 别人唱故乡,我不会唱 我只能写,写不出来,就喊 喊我的故乡 我的故乡在江南 我对着江南喊 用心...
    Lu_0412阅读 2,498评论 0 0

友情链接更多精彩内容