github创建
获取公钥
[root@localhost ~]# ssh-keygen
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:
ae:64:7a:21:91:73:4b:52:8f:4b:2f:08:50:2a:5f:bb root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
| .. |
|.. . |
|o. .o o |
|....=.= . |
| ...O +S |
| o.=.. |
| E.oo. |
| +.. |
| ... |
+-----------------+
[root@localhost ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDJTjJTm78zW2k2t+5DLUbBJ2G4Ie/P+0EarJZvx0wl8uVvkjx7taOPb7v3a3gQP947egyEHDPnfOiXQ64RCX7jMGlYDvxNjbVXyrgPtTwZIGji61HmgtdXx43JYOkj+uq5fJ/UhI7UgG9Q+n9NkubNxb3KxLyrjoydACAq23uwOqiU20zhXSExeJJvMf3p7iQCXJBF1Gr+SMyVDi0+RNvCsE8FsI6hNvw7PFqjSk1xRdeSRUGKAQ1vPRVPD9Ha8zef5ROr6YYWSfE5xJbR5YoD5xGH+7oKp3p+kG5wndsWuiCPBLwVOrwIb68gKJQl0Mrn1L0BZ+j62hrcnmWVGPtb root@localhost.localdomainistartor
初始化
[root@localhost ~]# cd /tmp/
[root@localhost tmp]# mkdir test
[root@localhost tmp]# cd test/
[root@localhost test]# echo "# test" >> README.md
[root@localhost test]# ls
README.md
[root@localhost test]# git init
Initialized empty Git repository in /tmp/test/.git/
[root@localhost test]# ls -la
total 8
drwxr-xr-x. 3 root root 33 Aug 3 13:56 .
drwxrwxrwt. 8 root root 99 Aug 3 13:56 ..
drwxr-xr-x. 7 root root 4096 Aug 3 13:56 .git
-rw-r--r--. 1 root root 7 Aug 3 13:56 README.md
添加README.md
[root@localhost test]# git add README.md
[root@localhost test]# git commit -m "add README.md"
[master (root-commit) ac97d4f] add README.md
Committer: root <root@localhost.localdomain>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 1 insertion(+)
create mode 100644 README.md
[root@localhost test]# git remote add origin https://github.com/hellopasswd/test.git
[root@localhost test]# git remote rm origin
[root@localhost test]# git remote add origin git@github.com:hellopasswd/test.git
> 使用https需要输入用户名和密码
推送远程
[root@localhost test]# git push -u origin master
The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is 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.
Counting objects: 3, done.
Writing objects: 100% (3/3), 224 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:hellopasswd/test.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin. #分支master设置为跟踪来自origin的远程分支master
网页刷新
[root@localhost test]# echo "test" > 1.txt
[root@localhost test]# git add 1.txt
[root@localhost test]# git commit -m "add 1.txt"
[master 20de0e0] add 1.txt
Committer: root <root@localhost.localdomain>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 1 insertion(+)
create mode 100644 1.txt
[root@localhost test]# git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 274 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:hellopasswd/test.git
ac97d4f..20de0e0 master -> master
网页刷新
更新远程仓库
[root@localhost test]# git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:hellopasswd/test
20de0e0..d3231be master -> origin/master
Updating 20de0e0..d3231be
Fast-forward
1.txt | 1 +
1 file changed, 1 insertion(+)
[root@localhost test]# cat 1.txt
test
111