windows下新增项目本地通过git bash推送至远程github
本地E盘workspace目录下新增了spring-cloud-alibaba-demo项目,还没有编译过,没有target等不需要推送至git的文件,所以就直接用git bash丢到github了。先在github上创建一个空项目,跟本地目录同名:
然后就纯命令行操作了,打开git bash:
wulf@wulf00 MINGW64 /c/Users $ cd e: wulf@wulf00 MINGW64 /e $ cd workspace/spring-cloud-alibaba-demo/ wulf@wulf00 MINGW64 /e/workspace/spring-cloud-alibaba-demo $ git init Initialized empty Git repository in E:/workspace/spring-cloud-alibaba-demo/.git/ wulf@wulf00 MINGW64 /e/workspace/spring-cloud-alibaba-demo (master) $ git remote add origin https://github.com/wuxun1997/spring-cloud-alibaba-demo.git wulf@wulf00 MINGW64 /e/workspace/spring-cloud-alibaba-demo (master) $ git add . warning: LF will be replaced by CRLF in pom.xml. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in spring-cloud-alibaba-consumer/pom.xml. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in spring-cloud-alibaba-consumer/src/main/resources/application.properties. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in spring-cloud-alibaba-gateway/pom.xml. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in spring-cloud-alibaba-provider/pom.xml. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in spring-cloud-alibaba-provider/src/main/java/com/wlf/alibaba/provider/TransProviderApplication.java. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in spring-cloud-alibaba-provider/src/main/resources/application.properties. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in spring-cloud-alibaba-provider/src/test/java/com/lingxicloud/lxytrans/provider/TransProviderApplicationTests.java. The file will have its original line endings in your working directory. wulf@wulf00 MINGW64 /e/workspace/spring-cloud-alibaba-demo (master) $ git commit -m "first commit" [master (root-commit) e75e0ee] first commit 13 files changed, 525 insertions(+) create mode 100644 pom.xml create mode 100644 spring-cloud-alibaba-consumer/pom.xml create mode 100644 spring-cloud-alibaba-consumer/src/main/java/com/wlf/alibaba/consumer/TransConsumerApplication.java create mode 100644 spring-cloud-alibaba-consumer/src/main/resources/application.properties create mode 100644 spring-cloud-alibaba-gateway/pom.xml create mode 100644 spring-cloud-alibaba-gateway/src/main/java/com/wlf/alibaba/gate/GatewayConfiguration.java create mode 100644 spring-cloud-alibaba-gateway/src/main/java/com/wlf/alibaba/gate/TransGatewayApplication.java create mode 100644 spring-cloud-alibaba-gateway/src/main/resources/application.yml create mode 100644 spring-cloud-alibaba-provider/pom.xml create mode 100644 spring-cloud-alibaba-provider/src/main/java/com/wlf/alibaba/provider/TestService.java create mode 100644 spring-cloud-alibaba-provider/src/main/java/com/wlf/alibaba/provider/TransProviderApplication.java create mode 100644 spring-cloud-alibaba-provider/src/main/resources/application.properties create mode 100644 spring-cloud-alibaba-provider/src/test/java/com/lingxicloud/lxytrans/provider/TransProviderApplicationTests.java wulf@wulf00 MINGW64 /e/workspace/spring-cloud-alibaba-demo (master) $ git push -u origin master Logon failed, use ctrl+c to cancel basic credential prompt. Username for 'https://github.com': wuxun1997 Counting objects: 48, done. Delta compression using up to 4 threads. Compressing objects: 100% (28/28), done. Writing objects: 100% (48/48), 5.81 KiB | 424.00 KiB/s, done. Total 48 (delta 6), reused 0 (delta 0) remote: Resolving deltas: 100% (6/6), done. To https://github.com/wuxun1997/spring-cloud-alibaba-demo.git * [new branch] master -> master Branch 'master' set up to track remote branch 'master' from 'origin'. wulf@wulf00 MINGW64 /e/workspace/spring-cloud-alibaba-demo (master) $
最后推送时校验了用户名和密码,上面标黄处是我们密码输错了,所以下面又重新输了下。如果你在github上创建仓库时也添加了README.md,那么提交时会报错:
wulf@wulf00 MINGW64 /e/workspace/spring-cloud-alibaba-demo (master) $ git push -u origin master To https://github.com/wuxun1997/spring-cloud-alibaba-demo.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/wuxun1997/spring-cloud-alibaba-demo' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
需要先把github上的READDE.md同步到本地后再提交:
wulf@wulf00 MINGW64 /e/workspace/spring-cloud-alibaba-demo (master) $ git pull --rebase 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/wuxun1997/spring-cloud-alibaba-demo * branch master -> FETCH_HEAD * [new branch] master -> origin/master First, rewinding head to replay your work on top of it... Applying: java spi
最后我们看到代码已经提交到git了:
另外通过IDEA推送的方式参见IDEA新建本地项目关联远程git仓库。