Github從賬號創(chuàng)建到上傳項目

目錄
1瀑踢、安裝git
MAC 上安裝Git主要有兩種方式
首先查看電腦是否安裝Git炒瘸,終端輸入:git
安裝過則會輸出:
iOSDevdeiMac:~ iosdev$ git
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 Reapply commits on top of another base tip
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.
iOSDevdeiMac:~ iosdev$
1萝风、通過homebrew安裝Git
1盖溺、安裝homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2、安裝git
brew install git
2铣除、通過Xcode安裝

直接從AppStore安裝Xcode,Xcode集成了Git鹦付,不過默認沒有安裝尚粘,你需要運行Xcode,選擇菜單“Xcode”->“Preferences”敲长,在彈出窗口中找到“Downloads”郎嫁,選擇“Command Line Tools”秉继,點“Install”就可以完成安裝了。

二泽铛、創(chuàng)建ssh key尚辑、配置git

1、設(shè)置username和email(github每次commit都會記錄他們)
git config --global user.name "wenbo"
git config --global user.email "1050794513@qq.com"
2盔腔、通過終端命令創(chuàng)建ssh key
ssh-keygen -t rsa -C "1050794513@qq.com"
1050794513@qq.com是我的郵件名杠茬,回車會有以下輸出
Last login: Sat Jan 6 14:12:16 on ttys000
WMBdeMacBook-Pro:~ WENBO$ ssh-keygen -t rsa -C "1050794513@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/WENBO/.ssh/id_rsa):
/Users/WENBO/.ssh/id_rsa already exists.
Overwrite (y/n)? n
WMBdeMacBook-Pro:~ WENBO$
這里我原來已經(jīng)創(chuàng)建過,這里我選n弛随,沒有創(chuàng)建過的瓢喉,會要求確認路徑和輸入密碼,我們這使用默認的一路回車就行舀透。成功的話會在~/下生成.ssh文件夾栓票,進去,打開id_rsa.pub愕够,復(fù)制里面的key走贪。
終端查看.ssh/id_rsa.pub文件
open .ssh/id_rsa.pub
回車后,就會新彈出一個終端惑芭,然后復(fù)制里面的key坠狡。
3、登錄GitHub(默認你已經(jīng)注冊了GitHub賬號)强衡,添加ssh key擦秽,點擊Settings,如圖

image.png

點擊New SSH key漩勤,如圖
image.png

添加key感挥,如圖
image.png

4、鏈接驗證
ssh -T git@github.com
終端輸出結(jié)果
Last login: Sat Jan 6 14:42:55 on ttys000
WMBdeMacBook-Pro:~ WENBO$ ssh -T git@github.com
Hi wenmobo! You've successfully authenticated, but GitHub does not provide shell access.
WMBdeMacBook-Pro:~ WENBO$
說明已經(jīng)鏈接成功越败。
三触幼、提交、上傳
1究飞、在GitHub上新創(chuàng)建一個 repository或者Start a Project置谦,如圖:
image.png

2、填寫項目信息亿傅,如下圖所示:
image.png

點擊Create repository,就創(chuàng)好一個工程了媒峡。
3、Clone工程到本地葵擎,首先復(fù)制ssh 地址
image.png

打開終端谅阿,這里只是測試,我想把工程克隆在桌面,首先在終端中切換路徑到桌面签餐,輸入以下命令:
cd /Users/WENBO/Desktop/
然后克隆項目,終端輸入
git clone git@github.com:wenmobo/LearnGit.git
git@github.com:wenmobo/LearnGit.git是剛剛復(fù)制的ssh路徑寓涨。
終端完整輸出如下:
Last login: Sat Jan 6 15:17:17 on ttys000
WMBdeMacBook-Pro:~ WENBO$ cd /Users/WENBO/Desktop/
WMBdeMacBook-Pro:Desktop WENBO$ git clone git@github.com:wenmobo/LearnGit.git
Cloning into 'LearnGit'...
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (5/5), 5.2
這時,工程已經(jīng)被克隆到桌面了氯檐,如下圖:

image.png

4戒良、在Xcode中新創(chuàng)建一個工程,保存的路徑為剛剛克隆下來的LearnGit文件夾下冠摄,如下圖所示:
image.png

5糯崎、提交修改,首先切換到LearnGit文件路徑:
cd /Users/WENBO/Desktop/LearnGit
然后輸入:
//文件添加到倉庫(.代表提交所有文件)
git add .
//把文件提交到倉庫
git commit -m "First Commit"
//上傳到github
git push
終端完整輸出如下:
Last login: Sat Jan 6 15:49:54 on ttys000
WMBdeMacBook-Pro:~ WENBO$ cd /Users/WENBO/Desktop/LearnGit
WMBdeMacBook-Pro:LearnGit WENBO$ git add .
WMBdeMacBook-Pro:LearnGit WENBO$ git commit -m "First Commit"
[master ae3bbe9] First Commit
11 files changed, 649 insertions(+)
create mode 100644 LearnGitDemo/LearnGitDemo.xcodeproj/project.pbxproj
create mode 100644 LearnGitDemo/LearnGitDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata
create mode 100644 LearnGitDemo/LearnGitDemo/AppDelegate.h
create mode 100644 LearnGitDemo/LearnGitDemo/AppDelegate.m
create mode 100644 LearnGitDemo/LearnGitDemo/Assets.xcassets/AppIcon.appiconset/Contents.json
create mode 100644 LearnGitDemo/LearnGitDemo/Base.lproj/LaunchScreen.storyboard
create mode 100644 LearnGitDemo/LearnGitDemo/Base.lproj/Main.storyboard
create mode 100644 LearnGitDemo/LearnGitDemo/Info.plist
create mode 100644 LearnGitDemo/LearnGitDemo/ViewController.h
create mode 100644 LearnGitDemo/LearnGitDemo/ViewController.m
create mode 100644 LearnGitDemo/LearnGitDemo/main.m
WMBdeMacBook-Pro:LearnGit WENBO$ git push
Warning: Permanently added the RSA host key for IP address '192.30.255.112' to the list of known hosts.
Counting objects: 20, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (18/18), done.
Writing objects: 100% (20/20), 6.80 KiB | 0 bytes/s, done.
Total 20 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), done.
To github.com:wenmobo/LearnGit.git
1000218..ae3bbe9 master -> master
WMBdeMacBook-Pro:LearnGit WENBO$
查看GitHub上的項目耗拓,LearnGit已經(jīng)上傳成功啦拇颅,如下圖所示:
image.png

注:
1、解決github push錯誤The requested URL returned error: 403 Forbidden while accessing
github push錯誤:
git push
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/wangz/future.git/info/refs
解決方案:cd到在clone下來的工程目錄下
vim .git/config
修改
[remote "origin"]
url = https://github.com/wangz/example.git

[remote "origin"]
url = https://wangz@github.com/wangz/example.git
再次git push乔询,彈出框輸入密碼樟插,即可提交

參考
http://www.reibang.com/p/7edb6b838a2e

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市竿刁,隨后出現(xiàn)的幾起案子黄锤,更是在濱河造成了極大的恐慌,老刑警劉巖食拜,帶你破解...
    沈念sama閱讀 219,539評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件鸵熟,死亡現(xiàn)場離奇詭異,居然都是意外死亡负甸,警方通過查閱死者的電腦和手機流强,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,594評論 3 396
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來呻待,“玉大人打月,你說我怎么就攤上這事〔献剑” “怎么了奏篙?”我有些...
    開封第一講書人閱讀 165,871評論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長迫淹。 經(jīng)常有香客問我秘通,道長,這世上最難降的妖魔是什么敛熬? 我笑而不...
    開封第一講書人閱讀 58,963評論 1 295
  • 正文 為了忘掉前任肺稀,我火速辦了婚禮,結(jié)果婚禮上应民,老公的妹妹穿的比我還像新娘话原。我一直安慰自己炸茧,他們只是感情好,可當我...
    茶點故事閱讀 67,984評論 6 393
  • 文/花漫 我一把揭開白布稿静。 她就那樣靜靜地躺著,像睡著了一般辕狰。 火紅的嫁衣襯著肌膚如雪改备。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,763評論 1 307
  • 那天蔓倍,我揣著相機與錄音悬钳,去河邊找鬼。 笑死偶翅,一個胖子當著我的面吹牛默勾,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播聚谁,決...
    沈念sama閱讀 40,468評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼母剥,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了形导?” 一聲冷哼從身側(cè)響起环疼,我...
    開封第一講書人閱讀 39,357評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎朵耕,沒想到半個月后炫隶,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,850評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡阎曹,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,002評論 3 338
  • 正文 我和宋清朗相戀三年伪阶,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片处嫌。...
    茶點故事閱讀 40,144評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡栅贴,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出锰霜,到底是詐尸還是另有隱情筹误,我是刑警寧澤,帶...
    沈念sama閱讀 35,823評論 5 346
  • 正文 年R本政府宣布癣缅,位于F島的核電站厨剪,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏友存。R本人自食惡果不足惜祷膳,卻給世界環(huán)境...
    茶點故事閱讀 41,483評論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望屡立。 院中可真熱鬧直晨,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,026評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至敛摘,卻和暖如春门烂,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背兄淫。 一陣腳步聲響...
    開封第一講書人閱讀 33,150評論 1 272
  • 我被黑心中介騙來泰國打工屯远, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人捕虽。 一個月前我還...
    沈念sama閱讀 48,415評論 3 373
  • 正文 我出身青樓慨丐,卻偏偏與公主長得像,于是被迫代替她去往敵國和親泄私。 傳聞我的和親對象是個殘疾皇子房揭,可洞房花燭夜當晚...
    茶點故事閱讀 45,092評論 2 355

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,336評論 0 10
  • 幸福之道第六天 男人需要的是陽剛之氣,女人需要的是陰柔之美晌端,所以男人女人都需要修煉自己的性能量崩溪。 今天第六天,今天...
    王楓浚閱讀 165評論 0 3
  • 我是個一如既往的隨心出行者斩松,5.13號突然決定帶家人出行伶唯,還好全家都是這種個性,一呼即應(yīng)惧盹,呵呵乳幸。 5.15晚 FM...
    Rose英杰閱讀 420評論 2 6
  • 一直想要鍛煉自己的口才,試了一些方法也看了一些文章钧椰,大多都感覺不切實際粹断,究其原因,應(yīng)該是那些鍛煉的方式或方法跟自己...
    李晏書閱讀 295評論 0 1
  • 親愛的小蟲 今天沒去現(xiàn)場看你們上課嫡霞,有些遺憾瓶埋。 但是,當我看到群里的關(guān)于你們的一組照片诊沪,新鮮欲滴的色彩帶來好強的視...
    240c6d9396b5閱讀 177評論 1 1