[root@dev01 ~/tlbb]# ssh-keygen -t rsa
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:0qgnmlRDJBMyAF8cfuEnVIRhLIW6jEchfCv49Q3RvEQ root@dev01
The key's randomart image is:
+---[RSA 2048]----+
|O +o+=*OE |
|.=.B+++.+ |
|..oo+.+o.. |
|..oo...=. |
| =.oo.ooS |
|. =. o... |
| .. o . |
| . o o |
| o |
+----[SHA256]-----+
[root@dev01 ~/tlbb]# cat /root/.ssh/
id_rsa id_rsa.pub known_hosts
[root@dev01 ~/tlbb]# cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC/ykeOue7gmKQg1jqYJ96d8gLWrC4GMVYFfDRsHUFB2wj4T2KvD4oLfTpa3HT4m2PbQpKlNR4vWfhIbbvCCp+o7/l6ZIAb5RnABG+czfAN4+1qaxtgAYfKCaxF0MISfUqvwrk979Ut9guJTJV+Yj+OcXeHQSYM0JTuYD8RRuVWr8SXAxdidvR+waicqospyZrHWYS+5Hyw0S/tk6UcTFU/EPhugU3Ff9sZGwpgphRyk5xUPgXRGXE2xlTsZucyngrRPb8aPe92k7er2zenwmRTiYsMgjhZB8TyumChsMR0MKwm7VqzOQuA79sanNNNVQ6U8ypJA7J3KeeTH65uUh/v root@dev01
3.普通用户使用普通分支推送仓库
[root@dev01 ~]# yum install -y git
[root@dev01 ~]# git config --global user.name "dev01"
[root@dev01 ~]# git config --global user.email "1@qq.com"
[root@dev01 ~]# git config --global color.ui true
[root@dev01 ~]# mkdir tlbb
[root@dev01 ~]# cd tlbb/
[root@dev01 ~/tlbb]# git init
Initialized empty Git repository in /root/tlbb/.git/
[root@dev01 ~/tlbb]# touch test.txt
[root@dev01 ~/tlbb]# git add *
[root@dev01 ~/tlbb]# git commit -m "add test.txt file"
[test 6b8e787] add test.txt file
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test.txt
[root@dev01 ~/tlbb]# git branch
* master
test
[root@dev01 ~/tlbb]# git branch -d test
warning: deleting branch 'test' that has been merged to
'refs/remotes/origin/test', but not yet merged to HEAD.
Deleted branch test (was 6b8e787).
[root@dev01 ~/tlbb]# git branch
* master
[root@dev01 ~/tlbb]#
[root@dev01 ~/tlbb]# git branch test
[root@dev01 ~/tlbb]# git branch
* master
test
[root@dev01 ~/tlbb]# git checkout test
D dev01.log
Switched to branch 'test'
[root@dev01 ~/tlbb]# git branch
master
* test
[root@dev01 ~/tlbb]# git push -u origin test #使用test分支推送
Counting objects: 6, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 449 bytes | 0 bytes/s, done.
Total 4 (delta 1), reused 0 (delta 0)
remote:
remote: To create a merge request for test, visit:
remote: http://10.0.0.100/Dev/tlbb/merge_requests/new?merge_request%5Bsource_branch%5D=test
remote:
To git@10.0.0.100:Dev/tlbb.git
* [new branch] test -> test
Branch test set up to track remote branch test from origin.
如果使用master分支会报错,因为我们设置了分支保护
[root@dev01 ~/tlbb]# touch 4.txt
[root@dev01 ~/tlbb]# git add *
[root@dev01 ~/tlbb]# git commit -m "add 4.txt file"
[master ac2b32a] add 4.txt file
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 4.txt
[root@dev01 ~/tlbb]# git push -u origin master
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 221 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: GitLab: You are not allowed to push code to protected branches on this project.
To git@10.0.0.100:Dev/tlbb.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@10.0.0.100:Dev/tlbb.git'