git上传项目

1.如何使用Git上传项目代码到github
2.Git新手入门与上传项目到远路仓库GitHub
3. github常见操作和常见错误!错误提示:fatal: remote origin already exists.
4.【已解决】github中git push origin master出错:error: failed to push some refs to
5.github上传时出现error: src refspec master does not match any解决办法
基本上按上面几篇文章来操作就可以了。
不过还是记录一下自己的具体步骤:
注意下面的步骤不包括git的配置安装过程,具体的配置安装请参考上述的博客,下面所述只是在安装配置成功后进行上传项目的步骤
1.先进入你要上传项目的根目录下,如F:\myprojects\springmvc Maven Webapp

lenovo@idea-PC MINGW64 ~
$ cd f:

lenovo@idea-PC MINGW64 /f
$ cd myprojects

lenovo@idea-PC MINGW64 /f/myprojects
$ cd springmvc Maven Webapp
bash: cd: springmvc: No such file or directory

lenovo@idea-PC MINGW64 /f/myprojects
$ cd "springmvc Maven Webapp"

2.初始化,创建了一个名为.git的文件夹

lenovo@idea-PC MINGW64 /f/myprojects/springmvc Maven Webapp
$ git init
Initialized empty Git repository in F:/myprojects/springmvc Maven Webapp/.git/

lenovo@idea-PC MINGW64 /f/myprojects/springmvc Maven Webapp (master)

3.git add . (将改动添加到暂存区)

lenovo@idea-PC MINGW64 /f/myprojects/springmvc Maven Webapp (master)
$ git add .
warning: LF will be replaced by CRLF in .mymetadata.
The file will have its original line endings in your working directory.
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 src/main/resources/spring-mybatis.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/main/webapp/WEB-INF/web.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/main/webapp/index.jsp.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in target/classes/spring-mybatis.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in target/m2e-jee/web-resources/META-INF/maven/org.springmvc/springmvc/pom.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in target/surefire-reports/TEST-net.cxp.test.TestMyBatis.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in target/surefire-reports/net.cxp.test.TestMyBatis.txt.
The file will have its original line endings in your working directory.

4.在你的github账户下新建一个repository ,注意这是在网页上进行,不是在本地进行
5.
千万记得下面说的“你的github用户名”不是你用$ git config –global user.name “your name”这句创建的用户名,而是你github账户上显示的用户名,后面的springmvc也是你在网页上(也就是服务器端)新建的仓库(create a new repository)。

touch README
git add README
git commit -m "first commit"
git remote add origin git@github.com:你的github用户名/springmvc.git
git push -u origin master

下面是具体显示

touch README
git add README
git commit -m "first commit"
[master (root-commit) 74ec194] first commit
 64 files changed, 3030 insertions(+)
 create mode 100644 .classpath
 create mode 100644 .mymetadata
 create mode 100644 .myumldata
 create mode 100644 .project
 create mode 100644 .settings/.jsdtscope
 create mode 100644 .settings/com.genuitec.eclipse.j2eedt.core.prefs
 create mode 100644 .settings/com.genuitec.jboss.ide.eclipse.xdoclet.run.prefs
 create mode 100644 .settings/org.eclipse.core.resources.prefs
 create mode 100644 .settings/org.eclipse.jdt.core.prefs
 create mode 100644 .settings/org.eclipse.m2e.core.prefs
 create mode 100644 .settings/org.eclipse.wst.common.component
 create mode 100644 .settings/org.eclipse.wst.common.project.facet.core.xml
 create mode 100644 .settings/org.eclipse.wst.jsdt.ui.superType.container
 create mode 100644 .settings/org.eclipse.wst.jsdt.ui.superType.name
 create mode 100644 README
 create mode 100644 logs/ssm.log
 create mode 100644 pom.xml
 create mode 100644 springmvc.sql
 create mode 100644 src/main/java/net/cxp/controller/GreetingController.java
 create mode 100644 src/main/java/net/cxp/controller/UsersController.java
 create mode 100644 src/main/java/net/cxp/dao/UsersMapper.java
 create mode 100644 src/main/java/net/cxp/mapping/UsersMapper.xml
 create mode 100644 src/main/java/net/cxp/pojo/Users.java
 create mode 100644 src/main/java/net/cxp/service/UsersService.java
 create mode 100644 src/main/java/net/cxp/service/impl/UsersServiceImpl.java
 create mode 100644 src/main/resources/jdbc.properties
 create mode 100644 src/main/resources/log4j.properties
 create mode 100644 src/main/resources/spring-mvc.xml
 create mode 100644 src/main/resources/spring-mybatis.xml
 create mode 100644 src/main/webapp/META-INF/MANIFEST.MF
 create mode 100644 src/main/webapp/WEB-INF/classes/net/cxp/controller/GreetingController.class
 create mode 100644 src/main/webapp/WEB-INF/classes/net/cxp/controller/UsersController.class
 create mode 100644 src/main/webapp/WEB-INF/classes/net/cxp/dao/UsersMapper.class
 create mode 100644 src/main/webapp/WEB-INF/classes/net/cxp/mapping/UsersMapper.xml
 create mode 100644 src/main/webapp/WEB-INF/classes/net/cxp/pojo/Users.class
 create mode 100644 src/main/webapp/WEB-INF/classes/net/cxp/service/UsersService.class
 create mode 100644 src/main/webapp/WEB-INF/classes/net/cxp/service/impl/UsersServiceImpl.class
 create mode 100644 src/main/webapp/WEB-INF/classes/net/cxp/test/TestMyBatis.class
 create mode 100644 src/main/webapp/WEB-INF/web.xml
 create mode 100644 src/main/webapp/greeting.jsp
 create mode 100644 src/main/webapp/index.jsp
 create mode 100644 src/main/webapp/showUser.jsp
 create mode 100644 src/test/java/net/cxp/test/TestMyBatis.java
 create mode 100644 target/classes/jdbc.properties
 create mode 100644 target/classes/log4j.properties
 create mode 100644 target/classes/net/cxp/controller/GreetingController.class
 create mode 100644 target/classes/net/cxp/controller/UsersController.class
 create mode 100644 target/classes/net/cxp/dao/UsersMapper.class
 create mode 100644 target/classes/net/cxp/mapping/UsersMapper.xml
 create mode 100644 target/classes/net/cxp/pojo/Users.class
 create mode 100644 target/classes/net/cxp/service/UsersService.class
 create mode 100644 target/classes/net/cxp/service/impl/UsersServiceImpl.class
 create mode 100644 target/classes/spring-mvc.xml
 create mode 100644 target/classes/spring-mybatis.xml
 create mode 100644 target/m2e-jee/web-resources/META-INF/MANIFEST.MF
 create mode 100644 target/m2e-jee/web-resources/META-INF/maven/org.springmvc/springmvc/pom.properties
 create mode 100644 target/m2e-jee/web-resources/META-INF/maven/org.springmvc/springmvc/pom.xml
 create mode 100644 target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
 create mode 100644 target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
 create mode 100644 target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst
 create mode 100644 target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst
 create mode 100644 target/surefire-reports/TEST-net.cxp.test.TestMyBatis.xml
 create mode 100644 target/surefire-reports/net.cxp.test.TestMyBatis.txt
 create mode 100644 target/test-classes/net/cxp/test/TestMyBatis.class

git remote add origin git@github.com:你的用户名/springmvc.git
git push -u origin master

出现

Counting objects: 116, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (78/78), done.
Writing objects: 100% (116/116), 30.65 KiB | 0 bytes/s, done.
Total 116 (delta 9), reused 0 (delta 0)
remote: Resolving deltas: 100% (9/9), done.
To github.com:chenxiaopan/springmvc.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

就说明成功了。

使用Git上传项目GitHub有两种方式,分别是SSH方式和https方式。SSH方式上传时无需输入账号和密码,https方式每次上传都需输入,若对安全性要求较高,可选择https方式,这里以SSH方式为例,假设环境为windows10且已有Github账号,详细过程如下: 1. **初始化本地仓库**:在项目根目录下执行`git init`命令,将当前目录初始化为一个Git仓库。 2. **添加文件到暂存区**:执行`git add .`,将当前目录下的所有文件添加到暂存区;也可使用`git add <文件名>`添加指定文件。这里可借助`.gitignore`文件,它能告诉git需要忽略的文件,避免将编译、调试等操作产生的中间文件和可执行文件添加到暂存区 [^4]。 3. **提交文件到本地仓库**:执行`git commit -m “XXX”`,将暂存区的文件提交到本地仓库,“XXX”为本次提交的描述信息 [^3]。 4. **关联远程仓库**:执行`git remote add origin git@github.com:changyan - maker/LoginApp.git`,将本地仓库与GitHub上的远程仓库进行关联,其中`git@github.com:changyan - maker/LoginApp.git`是远程仓库的SSH地址 [^1]。 5. **拉取远程仓库内容**:执行`git pull origin master --allow-unrelated-histories`,拉取远程仓库的内容到本地,并允许合并没有关联历史的分支 [^3]。 6. **上传本地代码到远程仓库**:执行`git push -u origin master`,将本地仓库的代码推送到GitHub的远程仓库。此过程可能需要输入一次密码或者输入yes,待提示上传完成,本地代码就已推送到github仓库 [^1]。 示例代码如下: ```bash # 初始化本地仓库 git init # 添加文件到暂存区 git add . # 提交文件到本地仓库 git commit -m "Initial commit" # 关联远程仓库 git remote add origin git@github.com:yourusername/yourrepository.git # 拉取远程仓库内容 git pull origin master --allow-unrelated-histories # 上传本地代码到远程仓库 git push -u origin master ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值