Github从账号创建到上传项目

目录
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”就可以完成安装了。

二、创建ssh key、配置git

1、设置username和email(github每次commit都会记录他们)
git config --global user.name "wenbo"
git config --global user.email "1050794513@qq.com"
2、通过终端命令创建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$
这里我原来已经创建过,这里我选n,没有创建过的,会要求确认路径和输入密码,我们这使用默认的一路回车就行。成功的话会在~/下生成.ssh文件夹,进去,打开id_rsa.pub,复制里面的key。
终端查看.ssh/id_rsa.pub文件
open .ssh/id_rsa.pub
回车后,就会新弹出一个终端,然后复制里面的key。
3、登录GitHub(默认你已经注册了GitHub账号),添加ssh key,点击Settings,如图

image.png

点击New SSH key,如图
image.png

添加key,如图
image.png

4、链接验证
ssh -T git@github.com
终端输出结果
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$
说明已经链接成功。
三、提交、上传
1、在GitHub上新创建一个 repository或者Start a Project,如图:
image.png

2、填写项目信息,如下图所示:
image.png

点击Create repository,就创好一个工程了。
3、Clone工程到本地,首先复制ssh 地址
image.png

打开终端,这里只是测试,我想把工程克隆在桌面,首先在终端中切换路径到桌面,输入以下命令:
cd /Users/WENBO/Desktop/
然后克隆项目,终端输入
git clone git@github.com:wenmobo/LearnGit.git
git@github.com:wenmobo/LearnGit.git是刚刚复制的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
这时,工程已经被克隆到桌面了,如下图:

image.png

4、在Xcode中新创建一个工程,保存的路径为刚刚克隆下来的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已经上传成功啦,如下图所示:
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,弹出框输入密码,即可提交

参考
https://www.jianshu.com/p/7edb6b838a2e

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 157,298评论 4 360
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,701评论 1 290
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 107,078评论 0 237
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,687评论 0 202
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,018评论 3 286
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,410评论 1 211
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,729评论 2 310
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,412评论 0 194
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,124评论 1 239
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,379评论 2 242
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,903评论 1 257
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,268评论 2 251
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,894评论 3 233
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,014评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,770评论 0 192
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,435评论 2 269
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,312评论 2 260

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,096评论 0 10
  • 幸福之道第六天 男人需要的是阳刚之气,女人需要的是阴柔之美,所以男人女人都需要修炼自己的性能量。 今天第六天,今天...
    王枫浚阅读 151评论 0 3
  • 我是个一如既往的随心出行者,5.13号突然决定带家人出行,还好全家都是这种个性,一呼即应,呵呵。 5.15晚 FM...
    Rose英杰阅读 391评论 2 6
  • 一直想要锻炼自己的口才,试了一些方法也看了一些文章,大多都感觉不切实际,究其原因,应该是那些锻炼的方式或方法跟自己...
    李晏书阅读 270评论 0 1
  • 亲爱的小虫 今天没去现场看你们上课,有些遗憾。 但是,当我看到群里的关于你们的一组照片,新鲜欲滴的色彩带来好强的视...
    240c6d9396b5阅读 154评论 1 1