将代码提交到github上托管的方式有一下几种:
(1)github上未建仓库
//在git上执行命令
echo "# abbc" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/XXX/xxx.git
git push -u origin master
在idea终端中执行代码后,成功上传到github仓库中。
huadeMacBook-Pro:springbootproject huayu$ echo "#springboot+maven+mybaits+druid">>README.md
huadeMacBook-Pro:springbootproject huayu$ git init
Initialized empty Git repository in /Users/huayu/Documents/workspace/springbootproject/.git/
huadeMacBook-Pro:springbootproject huayu$ git add README.md
huadeMacBook-Pro:springbootproject huayu$ git commit -m "first commit"
[master (root-commit) e4d1101] first commit
1 file changed, 1 insertion(+)
create mode 100644 README.md
huadeMacBook-Pro:springbootproject huayu$ git remote add origin https://github.com/Myuhua/springbootdemo.git
huadeMacBook-Pro:springbootproject huayu$ git push -u origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 235 bytes | 235.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
(2)github上已经建好了仓库
//在终端执行git命令
git remote add origin https://github.com/XXX/xxx.git
git push -u origin master
在终端执行代码后,成功上传github仓库中。
192:springbootproject huayu$ git remote add origin https://github.com/Myuhua/springbootdemo.git
192:springbootproject huayu$ ls
pom.xml springbootproject.iml src target
192:springbootproject huayu$ git push -u origin master
Counting objects: 100, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (91/91), done.
Writing objects: 100% (100/100), 16.58 KiB | 1.27 MiB/s, done.
Total 100 (delta 56), reused 0 (delta 0)
remote: Resolving deltas: 100% (56/56), done.
remote:
remote: Create a pull request for 'master' on GitHub by visiting:
remote: https://github.com/Myuhua/springbootdemo/pull/new/master
remote:
To https://github.com/Myuhua/springbootdemo.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
这是成功上传的到github的仓库截图,以前csdn传图片调整大小什么的都挺好用的,csdn改这版后上传图片调整大小费劲的要命!!我问了csdn的工作人员,图片大小调整功能暂时下线了, 大家先将就看吧,等他们修改上线后我再调整。
(3)在github仓库从另一个存储库导入代码,创建一个新的空仓库后,点击新创建的仓库,下面页面中有个import code按钮,进入后页面是这个样子的,然后你输入你的旧存储库的url将代码导入进来就可以了。(前提是github得支持的旧仓库才可以)
若有问题欢迎大家与我互动交流,如果文章帮到了你,请点小手指。另外,我的博客文章会不定期更新,喜欢的朋友可以加一下关注。