centos7 git配置及使用
centos7下git的使用和配置
第一种方法:
1.下载git,使用命令:
yum install git -y
2.配置git:
git config --global user.name "Your Name"
git config --global user.email "email@example.com"
git config --list #查看配置是否生效
3.Git生成本机SSH Key并添加到GitHub
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub
把这个pub里面的东西全部复制到 github右上角头像setting里ssh keys

4.测试一下该SSH key
ssh -T git@github.com

5.创建本地仓库:
mkdir test && cd test
git init
…or create a new repository on the command line
echo "# test" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/1233s2b/test.git
git push -u origin main
…or push an existing repository from the command line
git remote add origin https://github.com/1233s2b/test.git
git branch -M main
git push -u origin main
git修改远程仓库地址
方法有三种:
1.修改命令
git remote origin set-url [url]
先删后加
git remote rm origin
git remote add origin [url]
直接修改config文件
git文件夹,找到config,编辑,把就的项目地址替换成新的。
报错:remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
参考:https://blog.csdn.net/weixin_41010198/article/details/119698015
这时git本地仓库已经搭好了,测试一下:
创建1个readme,执行git status ./
readme已经加入暂存区,但还没提交本地仓库
再使用git commit提交:
git commit -m "add readme"
提交后查看,本地已经没有需要提交的记录。
git status ./
4.配置远程仓库:
提交远程仓库
git remote add origin git@gitlab.yonghui.cn:operation-s2b-009/ansible-ops.git
git push -u origin master
第二种方法:
同上1,2步
3.克隆远程版本库
git clone git@gitlab.yonghui.cn:operation-s2b-009/ansible-ops.git
git branch -a #查看显示所有本地分支
4.切换到指定的分支(默认分支master)
git checkout nginx
git branch -a #查看显示所有本地分支
5.添加改变的文件到暂存区
git add . #添加所有文件
git add +具体某个文件
6。提交本地仓库
git commit -m "redme"
git status ./
7.推送远程仓库
git push

浙公网安备 33010602011771号