1.打开GitHub,登录账号,然后新建一个仓位,(这个就不多说了)
2.打开Mac的终端,输入命令切换到本地需要上传代码的根目录,然后git初始化一下。这里我以自己的测试Demo为例:
1.cd /Users/jyeducation/Desktop/Demo
2.git init
Reinitialized existing Git repository in /Users/jyeducation/Desktop/Demo/.git/
3.在终端上输入命令,把整个代码添加,然后并通过命令写明提交代码的原因,具体如下
jyeducation@jingyingjiaoyudeMacBook-Pro Demo % git add .
jyeducation@jingyingjiaoyudeMacBook-Pro Demo % git commit -m"测试代码上传"
[master (root-commit) eb9ccb5] 测试代码上传
112 files changed, 11983 insertions(+)
create mode 100644 Demo.xcodeproj/project.pbxproj
create mode 100644 Demo.xcodeproj/project.xcworkspace/contents.xcworkspacedata
create mode 100644 Demo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
create mode 100644 Demo.xcodeproj/xcuserdata/jyeducation.xcuserdatad/xcschemes/xcschememanagement.plist
create mode 100644 Demo.xcworkspace/contents.xcworkspacedata
create mode 100644 Demo.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
create mode 100644 Demo/AppDelegate.h
create mode 100644 Demo/AppDelegate.m
create mode 100644 Demo/Assets.xcassets/AppIcon.appiconset/Contents.json
create mode 100644 Demo/Assets.xcassets/Contents.json
create mode 100644 Demo/Base.lproj/LaunchScreen.storyboard
create mode 100644 Demo/Base.lproj/Main.storyboard
create mode 100644 Demo/Info.plist
create mode 100644 Demo/SceneDelegate.h
create mode 100644 Demo/SceneDelegate.m
create mode 100644 Demo/ViewController.h
create mode 100644 Demo/ViewController.m
create mode 100644 Demo/main.m
create mode 100644 DemoTests/DemoTests.m
create mode 100644 DemoTests/Info.plist
create mode 100644 DemoUITests/DemoUITests.m
create mode 100644 DemoUITests/Info.plist
create mode 100644 Podfile.lock
create mode 100644 Pods/AFNetworking/AFNetworking/AFCompatibilityMacros.h
create mode 100644 Pods/AFNetworking/AFNetworking/AFHTTPSessionManager.h
create mode 100644 Pods/AFNetworking/AFNetworking/AFHTTPSessionManager.m
create mode 100644 Pods/AFNetworking/AFNetworking/AFNetworkReachabilityManager.h
create mode 100644 Pods/AFNetworking/AFNetworking/AFNetworkReachabilityManager.m
create mode 100644 Pods/AFNetworking/AFNetworking/AFNetworking.h
create mode 100644 Pods/AFNetworking/AFNetworking/AFSecurityPolicy.h
create mode 100644 Pods/AFNetworking/AFNetworking/AFSecurityPolicy.m
create mode 100644 Pods/AFNetworking/AFNetworking/AFURLRequestSerialization.h
create mode 100644 Pods/AFNetworking/AFNetworking/AFURLRequestSerialization.m
create mode 100644 Pods/AFNetworking/AFNetworking/AFURLResponseSerialization.h
create mode 100755 Pods/AFNetworking/AFNetworking/AFURLResponseSerialization.m
create mode 100644 Pods/AFNetworking/AFNetworking/AFURLSessionManager.h
create mode 100644 Pods/AFNetworking/AFNetworking/AFURLSessionManager.m
create mode 100644 Pods/AFNetworking/LICENSE
create mode 100644 Pods/AFNetworking/README.md
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/AFAutoPurgingImageCache.h
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/AFAutoPurgingImageCache.m
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/AFImageDownloader.h
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/AFImageDownloader.m
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/AFNetworkActivityIndicatorManager.h
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/AFNetworkActivityIndicatorManager.m
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/UIActivityIndicatorView+AFNetworking.h
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/UIActivityIndicatorView+AFNetworking.m
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/UIButton+AFNetworking.h
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/UIButton+AFNetworking.m
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/UIImage+AFNetworking.h
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/UIImageView+AFNetworking.h
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/UIImageView+AFNetworking.m
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/UIKit+AFNetworking.h
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/UIProgressView+AFNetworking.h
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/UIProgressView+AFNetworking.m
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/UIRefreshControl+AFNetworking.h
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/UIRefreshControl+AFNetworking.m
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/UIWebView+AFNetworking.h
create mode 100644 Pods/AFNetworking/UIKit+AFNetworking/UIWebView+AFNetworking.m
create mode 120000 Pods/Headers/Private/AFNetworking/AFAutoPurgingImageCache.h
create mode 120000 Pods/Headers/Private/AFNetworking/AFCompatibilityMacros.h
create mode 120000 Pods/Headers/Private/AFNetworking/AFHTTPSessionManager.h
create mode 120000 Pods/Headers/Private/AFNetworking/AFImageDownloader.h
create mode 120000 Pods/Headers/Private/AFNetworking/AFNetworkActivityIndicatorManager.h
create mode 120000 Pods/Headers/Private/AFNetworking/AFNetworkReachabilityManager.h
create mode 120000 Pods/Headers/Private/AFNetworking/AFNetworking.h
create mode 120000 Pods/Headers/Private/AFNetworking/AFSecurityPolicy.h
create mode 120000 Pods/Headers/Private/AFNetworking/AFURLRequestSerialization.h
create mode 120000 Pods/Headers/Private/AFNetworking/AFURLResponseSerialization.h
create mode 120000 Pods/Headers/Private/AFNetworking/AFURLSessionManager.h
create mode 120000 Pods/Headers/Private/AFNetworking/UIActivityIndicatorView+AFNetworking.h
create mode 120000 Pods/Headers/Private/AFNetworking/UIButton+AFNetworking.h
create mode 120000 Pods/Headers/Private/AFNetworking/UIImage+AFNetworking.h
create mode 120000 Pods/Headers/Private/AFNetworking/UIImageView+AFNetworking.h
create mode 120000 Pods/Headers/Private/AFNetworking/UIKit+AFNetworking.h
create mode 120000 Pods/Headers/Private/AFNetworking/UIProgressView+AFNetworking.h
create mode 120000 Pods/Headers/Private/AFNetworking/UIRefreshControl+AFNetworking.h
create mode 120000 Pods/Headers/Private/AFNetworking/UIWebView+AFNetworking.h
create mode 120000 Pods/Headers/Public/AFNetworking/AFAutoPurgingImageCache.h
create mode 120000 Pods/Headers/Public/AFNetworking/AFCompatibilityMacros.h
create mode 120000 Pods/Headers/Public/AFNetworking/AFHTTPSessionManager.h
create mode 120000 Pods/Headers/Public/AFNetworking/AFImageDownloader.h
create mode 120000 Pods/Headers/Public/AFNetworking/AFNetworkActivityIndicatorManager.h
create mode 120000 Pods/Headers/Public/AFNetworking/AFNetworkReachabilityManager.h
create mode 120000 Pods/Headers/Public/AFNetworking/AFNetworking.h
create mode 120000 Pods/Headers/Public/AFNetworking/AFSecurityPolicy.h
create mode 120000 Pods/Headers/Public/AFNetworking/AFURLRequestSerialization.h
create mode 120000 Pods/Headers/Public/AFNetworking/AFURLResponseSerialization.h
create mode 120000 Pods/Headers/Public/AFNetworking/AFURLSessionManager.h
create mode 120000 Pods/Headers/Public/AFNetworking/UIActivityIndicatorView+AFNetworking.h
create mode 120000 Pods/Headers/Public/AFNetworking/UIButton+AFNetworking.h
create mode 120000 Pods/Headers/Public/AFNetworking/UIImage+AFNetworking.h
create mode 120000 Pods/Headers/Public/AFNetworking/UIImageView+AFNetworking.h
create mode 120000 Pods/Headers/Public/AFNetworking/UIKit+AFNetworking.h
create mode 120000 Pods/Headers/Public/AFNetworking/UIProgressView+AFNetworking.h
create mode 120000 Pods/Headers/Public/AFNetworking/UIRefreshControl+AFNetworking.h
create mode 120000 Pods/Headers/Public/AFNetworking/UIWebView+AFNetworking.h
create mode 100644 Pods/Manifest.lock
create mode 100644 Pods/Pods.xcodeproj/project.pbxproj
create mode 100644 Pods/Pods.xcodeproj/xcuserdata/jyeducation.xcuserdatad/xcschemes/AFNetworking.xcscheme
create mode 100644 Pods/Pods.xcodeproj/xcuserdata/jyeducation.xcuserdatad/xcschemes/Pods-Demo.xcscheme
create mode 100644 Pods/Pods.xcodeproj/xcuserdata/jyeducation.xcuserdatad/xcschemes/xcschememanagement.plist
create mode 100644 Pods/Target Support Files/AFNetworking/AFNetworking-dummy.m
create mode 100644 Pods/Target Support Files/AFNetworking/AFNetworking-prefix.pch
create mode 100644 Pods/Target Support Files/AFNetworking/AFNetworking.debug.xcconfig
create mode 100644 Pods/Target Support Files/AFNetworking/AFNetworking.release.xcconfig
create mode 100644 Pods/Target Support Files/Pods-Demo/Pods-Demo-acknowledgements.markdown
create mode 100644 Pods/Target Support Files/Pods-Demo/Pods-Demo-acknowledgements.plist
create mode 100644 Pods/Target Support Files/Pods-Demo/Pods-Demo-dummy.m
create mode 100644 Pods/Target Support Files/Pods-Demo/Pods-Demo.debug.xcconfig
create mode 100644 Pods/Target Support Files/Pods-Demo/Pods-Demo.release.xcconfig
create mode 100644 podfile
(把整个代码提交到仓位,然后标注提交注释)
4.在终端上输入命令,连接远程的仓位,具体如下
jyeducation@jingyingjiaoyudeMacBook-Pro Demo % git remote add origin https://github.com/jackFantt/iosDemo.git
5.在终端上输入命令,拉一下远程的代码,如出现报错“fatal: refusing to merge unrelated
histories”,只需要在该命令行添加允许即可“--allow-unrelated-histories”,然后跳出文档说明,退出即可,具体如下
jyeducation@jingyingjiaoyudeMacBook-Pro Demo % git pull origin master
warning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/jackFantt/iosDemo
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
fatal: refusing to merge unrelated histories
jyeducation@jingyingjiaoyudeMacBook-Pro Demo % git pull origin master --allow-unrelated-histories
From https://github.com/jackFantt/iosDemo
* branch master -> FETCH_HEAD
Merge made by the 'recursive' strategy.
README.md | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 README.md
6.在终端上输入命令,把本地代码全部推送到远程仓库,具体如下
jyeducation@jingyingjiaoyudeMacBook-Pro Demo % git push origin master
或者(git push -u origin master)
Enumerating objects: 120, done.
Counting objects: 100% (120/120), done.
Delta compression using up to 8 threads
Compressing objects: 100% (114/114), done.
Writing objects: 100% (119/119), 116.86 KiB | 6.49 MiB/s, done.
Total 119 (delta 23), reused 0 (delta 0)
remote: Resolving deltas: 100% (23/23), done.
To https://github.com/jackFantt/iosDemo.git
8667454..f397830 master -> master
jyeducation@jingyingjiaoyudeMacBook-Pro Demo %
到GitHub之前新建的仓库里,刷新页面,即可看到刚刚上传的代码,具体如下图
到此,《Mac Git 学习教程 之 本地项目代码上传到GitHub》结束