Git 常用命令

Git global setup

1
2
git config --global user.name "Peak"
git config --global user.email "xxxxxx@xxx.xx"

Create a new repository

1
2
3
4
5
6
git clone http://47.105.160.77/php/media-e-commerce/station-face-sys.git
cd station-face-sys
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

Push an existing folder

1
2
3
4
5
6
cd existing_folder
git init
git remote add origin http://47.105.160.77/php/media-e-commerce/station-face-sys.git
git add .
git commit -m "Initial commit"
git push -u origin master

Push an existing Git repository

1
2
3
4
5
cd existing_repo
git remote rename origin old-origin
git remote add origin http://47.105.160.77/php/media-e-commerce/station-face-sys.git
git push -u origin --all
git push -u origin --tags

git clone an existing folder

1
2
3
git clone https://myrepo.com/git.git temp
mv temp/.git code/.git
rm -rf temp

生成 SSH 公钥

默认情况下,用户的 SSH 密钥存储在其 ~/.ssh 目录下

1
2
3
4
# cd ~/.ssh
# ls
authorized_keys2 id_dsa known_hosts
config id_dsa.pub

寻找一对以 id_dsaid_rsa 命名的文件,其中一个带有 .pub 扩展名的文件是你的公钥,另一个则是与之对应的私钥。

如果找不到这样的文件(或者根本没有 .ssh 目录),你可以通过运行 ssh-keygen 程序来创建它们。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# ssh-keygen -o
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:
2c:f3:3e:f1:68:34:45:b6:28:3f:0d:e2:2c:7b:4c:ab root@iz8vbh9uuqfp0767wn2527z
The key's randomart image is:
+--[ RSA 2048]----+
| |
| o |
| + . |
| o.o o |
| oo+S+ |
| . ++* . |
| = o.* |
| . +.+ . |
| Eo ... |
+-----------------+

查看公钥信息

1
2
]# cat ~/.ssh/id_rsa.pub 
ssh-rsa AAAA********************************

关于在多种操作系统中生成 SSH 密钥的更深入教程,请参阅 GitHub 的 SSH 密钥指南 https://help.github.com/articles/generating-ssh-keys

0%