云服务器CentOS7安装Git以及操作


centos 7上安装Git并进行基本操作的步骤如下:

 

1.安装Git:

可以通过yum命令简单地安装Git,这会自动安装所有依赖的包,并且通常会从源中安装最新的版本(但不一定是Git的最新版本)。

sudo yum install -y git

 

或者,您可以选择通过源码安装Git,这需要手动安装依赖包并从官网下载最新版本的Git源码包。以下是源码安装的步骤:

sudo yum install -y wget gcc-c++ zlib-devel perl-ExtUtils-MakeMaker

wget https://www.landui.com/pub/software/scm/git/git-2.9.0.tar.gz

tar -zxvf git-2.9.0.tar.gz

cd git-2.9.0

./configure –prefix=/usr/local

make

sudo make install

 

2.验证Git安装:

安装完成后,您可以通过以下命令来检查Git的版本,以确认安装成功:

git –version

 

3.Git基本配置:

设置Git的用户名称和邮箱,这对于提交代码是必要的:

git config –global user.name “Your Name”

git config –global user.email “email@example.com”

 

4.生成SSH公钥和私钥:

生成SSH密钥对,用于与GitHub等远程仓库通信,不需要密码:

ssh-keygen -t rsa -C “youremail@example.com”

 

5.Git仓库操作:

初始化Git仓库:

git init

 

添加文件到仓库并提交:

git add 文件名

git commit -m “说明”

 

查看仓库状态:

git status

 

推送代码到远程仓库:

git remote add origin git@server-name:path/repo-name.git

git push -u origin master

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享