(一.ssh的簡(jiǎn)單使用,二.push一個(gè)項(xiàng)目到GitHub)
一.生成ssh
1.首先查看當(dāng)前MAC的終端有沒(méi)有安裝GIT
根目錄下直接輸入:git
若顯示如下內(nèi)容愧沟,恭喜你已經(jīng)安裝git限府,不然需要在安裝一個(gè)git(這里就不細(xì)說(shuō)git的安裝過(guò)程)
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status
grow, mark and tweak your common history
branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Forward-port local commits to the updated upstream head
tag Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
2.已知MAC上git,接下來(lái)新建SSH-key(用來(lái)和github上連接)
終端輸入: ssh-keygen -t rsa -C your@mail.com
(此處填寫Github上的郵箱地址)
然后終端會(huì)顯示:
#這里以指定key例子(中間一直按Enter鍵)
Generating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa):
/home/git/.ssh/id_gitEnter passphrase (empty for no passphrase):
#密碼設(shè)置為空,如果設(shè)置了密碼,客戶端使用,需有記住此Key密碼的功能
Enter same passphrase again:
Your identification has been saved in /tmp/id_test.
Your public key has been saved in /tmp/id_test.pub.
The key fingerprint is:db:c8:37:24:56:08:b8:c5:d5:8e:f3:60:84:d6:fb:a0 root@i-25BDB9AF
The key's randomart image is:
+--[ RSA 2048]----+
| o.+.. |
| . =.o.. |
| + ..+. |
| . B.. |
| oS*. |
| Eo *o |
| + + |
| . . |
| |
+-----------------+
`到這里就已經(jīng)生成完了`
3.這時(shí)在終端輸入:ls -a(可以查看當(dāng)前所有的文件包括隱藏的,找到.ssh
的文件)
接著在終端輸入:open .ssh(打開(kāi)文件,找到id_rsa.pub
文件打開(kāi),復(fù)制里面的文件內(nèi)容)
4.打開(kāi)github點(diǎn)擊你的頭像\settings\SSH and GPG keys\New ssh key 這里的Title (可以隨意寫)key(把上個(gè)步驟復(fù)制的粘貼到這里)最后不要忘了Add SSH key.
二.push 一個(gè)項(xiàng)目到guthub
1.在Github上新建一個(gè)項(xiàng)目;
2.終端中輸入:cd 當(dāng)前項(xiàng)目的目錄
3.終端中輸入:git init (初始化)
4.終端中輸入:git add . (添加)
5.終端中輸入:git commit -m"(此處輸入與你項(xiàng)目有關(guān)的:如XX第一次提交)
"
6.終端中輸入:git remote add origin(此處填github上clone or downdload/Clone with ssh 上面的地址)
7.終端中輸入:git pull origin master
8.終端中輸入:git push origin master -f(直接推到github上)
會(huì)顯示類似如下的內(nèi)容:
Counting objects: 208, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (204/204), done.
Writing objects: 100% (208/208), 920.10 KiB | 147.00 KiB/s, done.
Total 208 (delta 25), reused 0 (delta 0)
remote: Resolving deltas: 100% (25/25), done.
To git@github.com:XXXXXXXXXXXXX
+ 53d955e...38d2198 master -> master (forced update)
```
這樣就已經(jīng)上傳成功了白嘁,可以到Github上看到你的項(xiàng)目了。