一、Git 安装使用

1、 Git 安装配置

1、Yum 安装 Git

  • Centos/RedHat 安装命令
[root@localhost ~]# yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
# yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
[root@localhost ~]# yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
# yum -y install git-core[root@localhost ~]#  git --version
git version 1.8.3.1

2、源码安装

  • 最新源码包下载地址:https://git-scm.com/download

  • 安装系统的依赖包:

[root@qfedu.com ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
  • 解压下载的源码包:
[root@qfedu.com ~]# tar -zxf git-2.9.5.tar.xz
[root@qfedu.com ~]# cd git-2.9.5
[root@qfedu.com ~]# make prefix=/usr/local all
[root@qfedu.com ~]# make prefix=/usr/local install

2、Git 配置

1、Git 用户信息

  • 配置个人的用户名称和电子邮件地址:
[root@localhost ~]# git config --global user.name "liqiufeng"
[root@localhost ~]# git config --global user.email 1922857947@qq.com

2、文本编辑器

  • 设置Git默认使用的文本编辑器, 一般可能会是 Vi 或者 Vim。如果你有其他偏好,比如 Emacs 的话,可以重新设置::
[root@qfedu.com ~]# git config --global core.editor emacs

3、查看配置信息

  • 要检查已有的配置信息,可以使用 git config --list 命令:
[root@localhost ~]# git config --list
user.name=liqiufeng
user.email=1922857947@qq.com
core.editor=emacs

二、安装本地 Git 服务器

1、创建用户初始化仓库

[root@localhost ~]# useradd git
[root@localhost ~]# passwd git
更改用户 git 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ~]# mkdir /git-root/
[root@localhost ~]# cd /git-root/
[root@localhost git-root]# git init --bare shell.git
初始化空的 Git 版本库于 /git-root/shell.git/

2、给项目添加权限推送公钥

[root@localhost git-root]# chown -R git:git /git-root/
[root@localhost git-root]# ll
总用量 0
drwxr-xr-x 7 git git 119 9月  25 20:13 shell.git
[root@localhost git-root]# ssh-keygen
[root@localhost git-root]# ssh-copy-id git@192.168.122.11

3、拉取项目推送内容测试

[root@localhost git-root]# cd /opt/
[root@localhost opt]# ls
[root@localhost opt]# git clone git@192.168.122.11:/git-root/shell.git/
正克隆到 'shell'...
warning: 您似乎克隆了一个空版本库。
[root@localhost opt]# ls
shell
[root@localhost opt]# cd shell/
[root@localhost shell]# vim test.sh
[root@localhost shell]# git add .
[root@localhost shell]# git commit -m 'first commit'
[master(根提交) 3376488] first commit1 file changed, 2 insertions(+)create mode 100644 test.sh
[root@localhost shell]# git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 235 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.122.11:/git-root/shell.git/* [new branch]      master -> master

2、Git 使用

我们在客户机进行操作,首先安装git:

[root@node-1 ~]# yum -y install git-core

1、ssh 链接

  • 客户机上产生公钥上传到gitlab的SSH-Keys里,git clone下载和git push上传都没问题,这种方式很安全

2、 执行命令设置登录用户和密码

#cd到根目录,执行
[root@node-1 ~]# git config --global credential.helper store  # 执行之后会在.gitconfig文件中多添加以下选项[credential]         helper = store
# cd到项目目录,执行git pull命令,会提示输入账号密码。输完这一次以后就不再需要,并且会在根目录生成一个.git-credentials文件
### 3、设置身份验证- **注意:**设定本机用户名,绑定邮箱,让远程服务器知道机器的身份```shell
[root@node-1 ~]#  git config --global user.name "user-1"
[root@node-1 ~]# git config --global user.email "test@qq.com"

3、本地项目与远程服务器项目之间的交互

1、如果你没有最新的代码,希望从头开始

[root@node-1 ~]#  git clone git@192.168.122.11:/git-root/shell.git      # 这里是项目的地址(可从项目主页复制),将远程服务器的内容完全复制过来
[root@node-1 ~]# cd shell                   # clone 之后进入该项目的文件夹
[root@node-1 shell]# echo "hello world" > README.txt           # 新建readme文件
[root@node-1 shell]# ls
README.txt  test.sh
[root@node-1 shell]# git add README.md          # 将新的文件添加到git的暂存区
[root@node-1 shell]# git commit -m 'Its note:add a readme file'
[master 5609349] Its note:add a readme file1 file changed, 1 insertion(+)create mode 100644 README.txt# 将暂存区的文件提交到某一个版本保存下来,并加上注释
[root@qfedu.com ~]# git push -u origin master
Counting objects: 4, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 294 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.122.11:/git-root/shell.git3376488..5609349  master -> master
分支 master 设置为跟踪来自 origin 的远程分支 master。
# 将本地的更改提交到远程服务器

2、如果你已经有一个新版代码,希望直接把本地的代码替换到远程服务器

[root@node-1 ~]# cd existing_folder          #进入代码存在的文件夹,或者直接在该文件夹打开
[root@node-1 ~]# git bash git init           # 初始化
[root@node-1 ~]# git remote add origin git@XXX.git  #添加远程项目地址(可从项目主页复制)
[root@node-1 ~]# git add .                   #添加该文件夹中所有的文件到git的暂存区
[root@node-1 ~]# git commit -m ‘note’        #提交所有代码到本机的版本库
[root@node-1 ~]# git push -u origin master   #将本地的更改提交到远程服务器
  • git 中 clone过来的时候,git 不会对比本地和服务器的文件,也就不会有冲突,

  • 建议确定完全覆盖本地的时候用 clone,不确定会不会有冲突的时候用 git pull,将远程服务器的代码download下来

三、Github 远程仓库

1、github.com 注册账户

2、github 上创建仓库

3、本地服务器生成 ssh 公钥

[root@localhost ~]# ssh-keygen -t rsa -C '1922857947@qq.com'  # 邮箱要与github上注册的相同
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:RiE6UR1BtzV5avyE2uz6TNPsVHa2D2eHprghrJEkd/g meteor@163.com
The key's randomart image is:
+---[RSA 2048]----+
|    ..oo=o. o.   |
|     o ..o o...  |
|    o   . .. +   |
|     . o    = .  |
|    . + S  = o  =|
|     + *  . oo.=o|
|      o E ..o B.+|
|       o . =.* +o|
|      .   +++ . .|
+----[SHA256]-----+[root@localhost ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDVThfq4brrlsPGtAknVB0TLPx+7Dd3qlxTbSIrUOsGC5Y8JuNqVTlIntZB4oNj8cSQrWvec9CKm0a8o7WwaJIiqpxurz+YpQHP2KbapftKIxsX4hPf/z+p0El1U6arQa35/xmNsq+cJLH/bDdRG+EMDhuCBmjVZOlLj/hEdeIT6s56AnnCkaWoF+sq58KCF7Tk54jRbs/YiyE4SN7FuA70r+07sA/uj0+lmuk4E190KtQUELhjX/E9stivlqiRhxnKvVUqXDywsjfM8Rtvbi4Fg9R8Wt9fpd4QwnWksYUoR5qZJFYXO4hSZrUnSMruPK14xXjDJcFDcP2eHIzKgLD1 1922857947@qq.com

4、 github 添加 ssh 公钥

  • 复制以上的公钥,在 github 中添加ssh key

5、测试连接

[root@localhost ~]# yum install git
........
[root@localhost ~]# ssh -T git@qfedu.comhub.com
The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
RSA key fingerprint is MD5:16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts.
Hi meteor! You've successfully authenticated, but GitHub does not provide shell access.

6、连接远程仓库(创建一个测试存储库)

# 在 github 网站新建一个仓库,命名为linux
~~~
[root@localhost ~]# cd /opt
[root@localhost ~]# mkdir linux
[root@localhost ~]# cd linux
~~~
# git 初始化,然后做第一个基本的git操作(需要在github上创建存储库)
[root@localhost linux]# git init
[root@localhost linux]# touch README
[root@localhost linux]# git add README
[root@localhost linux]# git commit -m 'first commit'
[root@localhost linux]# git remote add origin git@liqiufeng.comhub.com:userhub/linux.git
~~~
# 若出现origin已经存在的错误,删除origin
[root@qfedu.com linux]# git remote rm origin
# 现在继续执行push到远端
~~~
[root@localhost linux]# git remote add origin git@liqiufeng.comhub.com:userhub/l[root@localhost ~]inux.git
[root@localhost linux]# git push -u origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 205 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@liqiufeng.comhub.com:fakehydra/linux-.git* [new branch]      master -> master
分支 master 设置为跟踪来自 origin 的远程分支 master。
# 注意
# 设置存储库链接
[root@localhost ~]# git remote set-url origin git@liqiufeng.comhub.com:userhub/linux.git
# 如果 push 失败,合并分支到 master 再 push
[root@localhost~]# git pull --rebase origin master

Git 安装使用 本地Git 服务器的使用 Github 远程仓库相关推荐

  1. Git如何创建本地分支并推送到远程仓库

    Git如何创建本地分支并推送到远程仓库 假设新的分支名称为:new_branch -- 切换到拉取分支的原分支,假设为master git checkout master git pull -- 拉取 ...

  2. 版本控制介绍、Git的安装、TortoiseGit的安装、Git的文件操作、IDEA + 同步到GitHub远程仓库 | 克隆 | 分支 | 忽略文件

    文章目录 版本控制 什么是版本控制 常见的版本控制工具 版本控制分类 Git与SVN的主要区别 Git的历史 Git安装与配置 TortoiseGit的安装 Git基本理论 Git项目搭建 Git文件 ...

  3. Git使用方法(将本地文件上传到github远程仓库)

    此文章对于Git的使用介绍的很详细,对于新手很是友好哦.(实测没问题) Git的安装就不说了. 第一步:我们需要先创建一个本地的版本库(其实也就是一个文件夹). 你可以直接右击新建文件夹,也可以右击打 ...

  4. git学习-如何将本地项目上传(同步)到github远程仓库

    初学github想要把自己做过的online judge题解上传到github上去.有两种方法, 一,直接在github网页上完成创建代码文件并编写,比较容易. 二,是本地编写完代码,放到本地仓库,然 ...

  5. 【git教程】git安装、本地仓库与远程仓库使用详细指南

    git版本控制工具 下载地址:https://www.git-scm.com/download/win 选择对应版本的工具,下载后是一个exe执行文件: 本文使用到的git命令 命令 作用 git a ...

  6. GIT(一):版本控制、git历史、git基本概念、git安装配置、git版本管理(本地和远程)、git分支管理

    目录 一.版本控制 1.1 版本控制概念 1.2 版本控制软件分类 1.2.1 集中式版本控制 1.2.2 分布式版本控制 二.git历史 三.GIT基本概念 3.1 GIT原理 3.1.1 GIT基 ...

  7. 第二:Git如何将本地项目上传到Github(超详解)

    一.第一种方法:(自测可以实现) 1.首先你需要一个github账号,所以还没有的话先去注册吧! https://github.com/ 我们使用git需要先安装git工具,这里给出下载地址,下载后一 ...

  8. git 安装_Windows系统Git安装教程(详解Git安装过程)

    今天更换电脑系统,需要重新安装Git,正好做个记录,希望对第一次使用的朋友能有所帮助! 获取Git安装程序 到Git官网下载,网站地址:https://git-scm.com/downloads 因为 ...

  9. Git学习(了解版本控制、Git安装配置、Git基本理论、Git搭建、Git文件操作、使用码云或Github、IDEA集成Git,Git分支开发)

    学习git之前,我们需要先明白一个概念,版本控制! 版本控制 什么是版本控制 版本迭代,新的版本!版本管理器. 版本控制(Revision Control)是一种在开发的过程中用于管理我们对文件.目录 ...

最新文章

  1. c语言邻接表的构建_c语言数据结构--图的邻接矩阵和邻接表操作的基本操作
  2. 17个服务器发展趋势,我们都给您总结好了!
  3. SAP Fiori My task里complete checkbox的处理
  4. 用java求直角三角形的面积_JAVA 已知三角形的三个边判断 是否为直角三角形,如果是求面积!...
  5. 物联网现状及落地难点
  6. 笨办法学 Python · 续 练习 34:分析器
  7. OpenCV图像处理篇之边缘检測算子
  8. vue05-REST 请求
  9. 如何用EasyRecovery恢复中毒U盘中丢失的文件
  10. 荔枝直播助手无法连接到服务器,荔枝FM直播助手pc客户端
  11. 专利检索常用的网站有哪些?
  12. C语言按行列加密解密(英文文本)
  13. 铅蓄电池首批规范企业名单出炉 多家上市公司入围
  14. element-ui 表格合并问题
  15. ONF测试工作张攀:OpenFlow控制器性能测试工具进展
  16. 超融合兼顾医疗信创及 IT 云化转型的可行性分析
  17. HTML5游戏开发实战
  18. 美股历史行情数据 API 接口
  19. 论文笔记_SIGGRAPH2019会前课程:An Introduction to Physics-Based Animation_1
  20. 混迹在腾讯微博的知名站长名单(截至4月28日)

热门文章

  1. word转图片 java_Java MS Word和PDF转换为图像(png / jpg)
  2. ORACLE中的多表连接查询
  3. 使用PHPMailer发送outlook邮件
  4. ssbdemod在matlab中的意义,matlab中modulate函数
  5. 硬盘格式化工具,强烈推荐这个!
  6. 2017大学生程序设计邀请赛(华东师范大学) A.拼音魔法
  7. oracle默认管理员的帐号和密码
  8. 极客日报第 33 期:美团回应“大数据杀熟”;Docker开发者预览版支持M1芯片
  9. 基于SpringBoot+微信小程序的社区平台
  10. java32位玩我的世界卡_玩我的世界卡顿怎么设置