前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Git建立远程/本地服务器和Git命令的使用

Git建立远程/本地服务器和Git命令的使用

作者头像
星哥玩云
发布2022-07-13 15:34:30
2.7K0
发布2022-07-13 15:34:30
举报
文章被收录于专栏:开源部署

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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档