Git建立远程/本地服务器和git命令的使用
Github 远程仓库
1、github.com 注册账户
2、在github上创建仓库
3、生成本地ssh key
[root@localhost ~]# ssh-keygen -t rsa -C 'maiya@163.com' # 邮箱要与github上注册的相同
[root@localhost ~]# cat .ssh/id_rsa.pub
ssh-rsa
AAAAB3NzaC1yc2EAAAADAQABAAABAQDVThfq4brrlsPGtAknVB0TLPx+7Dd3qlxTbSIrUOsGC5Y8JuNqVTlIntZB
4oNj8cSQrWvec9CKm0a8o7WwaJIiqpxurz+YpQHP2KbapftKIxsX4hPf/z+p0El1U6arQa35/xmNsq+cJLH/bDdR
G+EMDhuCBmjVZOlLj/hEdeIT6s56AnnCkaWoF+sq58KCF7Tk54jRbs/YiyE4SN7FuA70r+07sA/uj0+lmuk4E190
KtQUELhjX/E9stivlqiRhxnKvVUqXDywsjfM8Rtvbi4Fg9R8Wt9fpd4QwnWksYUoR5qZJFYXO4hSZrUnSMruPK14
xXjDJcFDcP2eHIzKgLD1 maiya@163.com
4、复制以上的公钥,在github 中添加ssh key
5、测试
[root@localhost ~]# yum install git
........
[root@localhost ~]# ssh -T git@github.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、在本地添加远程仓库
[root@localhost ~]# git config --global user.name 'maiya_by'
[root@localhost ~]# git config --global user.email 'maiya@163.com'
[root@localhost ~]# git config --global color.ui true
[root@localhost ~]# git config --list | tail -3
user.name=maiya_by
user.email=maiya@163.com
color.ui=true
[root@localhost ~]#
[root@localhost ~]# ls .gitconfig
.gitconfig
[root@localhost ~]# cat .gitconfig
[user]
name = maiya_by
email = maiya@163.com
[color]
ui = true
7、连接远程仓库听方法
[root@localhost python1804]# git remote -v
origin git@github.com:meteor/python1804.git (fetch)
origin git@github.com:meteor/python1804.git (push)
[root@localhost python1804]#git remote rm origin(如果连接远程的方式不是ssh,可以删除重新添加)
[root@localhost ~]# git remote add origin git@github.com:meteor/python1804.git
或
git remote add origin https://github.com/meteor/python1804.git
git push -u origin master
建立本地Git 服务器
[root@localhost ~]# useradd git ------------------创建一个git用户
[root@localhost ~]# mkdir /git‐root/
[root@localhost ~]# cd /git‐root/
[root@localhost git‐root]# git init ‐‐bare shell.git --------------初始化仓库
[root@localhost git‐root]# chown ‐R git.git shell.git ----------把文件的属主和属组改成git
[root@localhost git‐root]# su ‐ git --------------切换成git用户
生成密钥
[git@localhost ~]$ ssh‐keygen ‐t rsa ----------------生成密钥
[git@localhost ~]$ cd .ssh/
[git@localhost .ssh]$ cp id_rsa.pub authorized_keys-----------新建授权公钥串
[git@localhost .ssh]$ exit
克隆仓库
[root@localhost ~]# cd /opt/
[root@localhost opt]# git clone git@192.168.1.102:/git‐root/shell.git-----------克隆本地仓库
Cloning into 'shell'...
新建一个测试文件,进行推送
[root@localhost opt]# cd shell/
[root@localhost shell]# vim test1.sh
[root@localhost shell]# git add test1.sh
[root@localhost shell]# git commit ‐m 'first commit'
[root@localhost shell]# git push origin master
git常用的命令
git
git init #------------------初始化仓库
git clone https://github.com/kennethreitz/requests.gitCloning into 'requests'... #-----克隆建立远程库
git clone git@192.168.122.85:/git-root/liudelong.git #-------克隆建立本地库
git add * #------------提交
git commit -m "describe" #---------------对提交任务进行描述
git push origin master #----------------上传
查看状态
git status #------------------查看git 的状态
git status -s #-------------------查看git 的简要信息
显示信息:
A .gitignore
MM test2.py #------------------第一个M表示staging有修改,第二个M表示working directory有修改
git diff #检查数据是否一致
git diff #-------------默认git diff 只检查第二个标志位(即检查working directory与staging的数据是否一致
git diff HEAD #-------------------指针,检查working directory与history是否一致,HEAD指针就指向最后一次提交的内容
git diff --stat #-----------------输出简要信息
git diff --staged #-----------------表示检查stage与history中的数据是否一致
下载
git reset #----------------下载历史history中的最后一个版本致stage中
git checkout #--------------------把历史区的文件恢复到工作区-下载stage中的数据到working directory
git checkout HEAD #------------------从history中直接下载历史版本到working directory
git commit -am 'third commit' #-----------------直接由working directory提交到history
删除数据:
git rm file #--------------------删除文件
git rm --cached test2.py #---------------仅删除staging中的文件,此命令主要用来修改文件名
stash暂存
git stash #-------------暂存当前正在进行的工作
git stash list #----------------查看之前的暂存区
git stash pop #----------------取出上次的暂存
branch分支
git branch #----------------查看分支 (*表示当前的 branch)
git branch newidea #----------------创建分支
git checkout newidea #---------------切换新的分支
cat .git/HEAD #----------------查看当前HEAD指向newidea分支
ls .git/refs/heads/ #----------查看现有分支的存储情况
cat .git/refs/heads/* #---------------查看两个分支都指向同一个commit history
git branch -d newidea #-----------------删除指定分支
git checkout -b newcode #------------------参数-b 作用:检查如果没有branch则新建立
git merge newcode #--------------合并分支
git merge bugfix #--------------合并分支Auto-merging test1.py
转载于:https://blog.51cto.com/13581826/2096322
Git建立远程/本地服务器和git命令的使用相关推荐
- Git建立远程代码仓库和本地代码仓库
Git建立远程代码仓库和本地代码仓库 使用Git管理代码,需要有两个仓库.一个是远程代码仓库,一个是本地代码仓库. 远程仓库是用来托管代码的平台,比如说Github,GitLab,Gerrit,码云G ...
- git连接远程仓库码云及命令详解
git连接远程仓库码云及命令详解 1.前言 2.码云远程仓库(github同理) 1.注册码云账号 2.新建仓库 3.git工具的安装配置 1.git 工具下载配置 2.SHH公钥配对 4.创建 gi ...
- git hook 自动部署 linux git本地服务器搭建 git root 目录 git 仓库 git root/ .git
服务器自动部署项目之GitHooks神器 - CSDN博客 -- 每次都是将本地将代码push到远程仓库,然后再ssh到服务器上git pull,甚是麻烦.在项目开发中使用git的时候,push之后, ...
- git 从远程主服务器当中创建新分支
现有版本; h20, h28,h26,i8 h28,h26,i8是从H20下面创建的. 需求: 从H28下面创建新分支继续开发. 思路: 所有代码均是放置到H20上仓库当中,首先下载H20完整仓库,也 ...
- 使用git建立远程仓库,让别人git clone下来
首先, 如果你的ssh没有安装的话,要安装ssh服务端.ubuntu是很简单 sudo apt-get install openssh-server 1 , 建立你的 git 目录. ourunix ...
- 无废话Git——概念与本地服务器提交
Git是什么? 集中式与分布式 Git 的获取与安装 本地服务器中使用Git 暂存区(缓存区) Git是什么? Git是一个开源的分布式版本控制系统(也可以叫工具或是软件). 版本控管工具对于开发人员 ...
- IDEA新建本地项目关联远程本地仓库和git仓库详细步骤
创建本地项目,配置maven 创建本地Git仓库 将本地项目提交到本地仓库 连接远程仓库 创建本地项目,配置maven 创建本地Git仓库 选择Git-->Create Git Reposito ...
- git pull 覆盖本地_SVN与Git比较的优缺点差异
一. 集中式vs分布式 1. Subversion属于集中式的版本控制系统 集中式的版本控制系统都有一个单一的集中管理的服务器,保存所有文件的修订版本,而协同工作的人们都通过客户端连到这台服务器,取出 ...
- Pssh -- 使用单个终端在多个远程Linux服务器上执行命令
OpenSSH毫无疑问是可用于Linux的使用最广泛和强大工具之一,它允许你通过一个shell安全地连接到远程Linux系统,并且允许你与远程系统之间来回传输文件. 但OpenSSH的最大缺点是你不同 ...
最新文章
- 【bzoj1251】序列终结者(伸展树)
- 这个最基本的生命细节才被揭开——25毫秒核孔穿梭
- php_os用法,PHP教程:PHPUnit学习笔记(二)PHPUnit基本用法
- 全新的互动广告牌,待遇男女有别
- c#.net 获取时间日期年月日时分秒生成自动文件名格式
- 【NLP】全面详解 | 深度学习中的注意力机制(一)
- c++二叉树的层序遍历_leetcode 103. 二叉树的锯齿形层序遍历
- 把github转至gitee
- 数字证书转换cer---pem
- PHP数据处理:合并数据、详情数据
- 收入没有大幅增加,苹果提高手机价格影响销量
- lumion实例渲染6.2
- 平板xmind怎么添加父主题_XMind8主题使用教程
- php 监听redis,php监听redis key失效触发回调事件_后端开发
- JavaScript事件驱动模型
- 转: 学习开源项目的若干建议(infoq)
- Web应用多账号系统设计及微信扫码登录实现
- 如何利用市场细分方法构建更好的预测模型?
- Lua脚本编写Wireshark插件解析第三方私有协议
- Arduino IDE 玩转STM32 - 搭环境、刷固件、烧程序