最新 本地代码托管到GitHub 操作

1. 初始化本地库: 在要进行托管项目的根目录里打开git bash命令窗 使用git init 命令初始化,初始化之后使用 git app * (新增的文件必须要 add,更新的文件可以直接commit)和 git commit -m “first commit” 把文件提交到本地资源库;
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2.推送到远程库: 在GitHub 官网自己的新建与项
目对应的资源库,复制远程库地址,我这里使用的是https 方式:,在本地新增远程库地址及别名。然后就可以进行 push 将本地库提交到远程库,说明:**从2020年10月1日起GitHub 将使用main作为默认分支名,不再使用master分支,所以在推送时要push 到 main分支,在push前也要把本地分支名改为 main,不然会报错。**并且GitHub现在对Windows系统的验证方式也有所改变
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

3.拉取远程库代码: 使用 git pull origin main 可以拉取远程库代码,如果 只是用 git pull 或者 git push 命令现在会报错,如果使用iDea拉取代码也会报同样的错如下图红框内。
意思是:没有当前分支的跟踪信息。请指定要与哪个分支合并。
我们现在的分支并没有和远程分支绑定关系,拉取和提交的时候都要指定分支,所以设置一下绑定关系就可以不用指定分支了;

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

git branch --set-upstream-to=origin/main main
在这里插入图片描述
在这里插入图片描述

heizhishi@LAPTOP-65FKBFN1 MINGW64 /e/java/IDEAProject/yxz-io
$ git init
Initialized empty Git repository in E:/java/IDEAProject/yxz-io/.git/

heizhishi@LAPTOP-65FKBFN1 MINGW64 /e/java/IDEAProject/yxz-io (master)
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .idea/
        pom.xml
        src/
        yxz-io.iml

nothing added to commit but untracked files present (use "git add" to track)

heizhishi@LAPTOP-65FKBFN1 MINGW64 /e/java/IDEAProject/yxz-io (master)
$ git add *
The following paths are ignored by one of your .gitignore files:
target
Use -f if you really want to add them.
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/java/com/example/yxz/YxzIoAppli                    cation.java.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/test/java/com/example/yxz/YxzIoAppli                    cationTests.java.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in yxz-io.iml.
The file will have its original line endings in your working directory.
heizhishi@LAPTOP-65FKBFN1 MINGW64 /e/java/IDEAProject/yxz-io (master)
$ git commit -m "first commit"
[master (root-commit) c95ad1c] first commit
 12 files changed, 936 insertions(+)
 create mode 100644 pom.xml
 create mode 100644 src/main/java/com/example/yxz/YxzIoApplication.java
 create mode 100644 src/main/java/com/example/yxz/config/CustomMVCConfiguration.                    java
 create mode 100644 src/main/java/com/example/yxz/config/MvcConfig.java
 create mode 100644 src/main/java/com/example/yxz/config/MyWebAppConfigurer.java
 create mode 100644 src/main/java/com/example/yxz/controller/FileManageControlle                    r.java
 create mode 100644 src/main/java/com/example/yxz/util/VideoUtil.java
 create mode 100644 src/main/resources/application.properties
 create mode 100644 src/main/resources/jboss.jks
 create mode 100644 src/main/resources/logback-spring.xml
 create mode 100644 src/test/java/com/example/yxz/YxzIoApplicationTests.java
 create mode 100644 yxz-io.iml

heizhishi@LAPTOP-65FKBFN1 MINGW64 /e/java/IDEAProject/yxz-io (master)
$ git remote add origin https://github.com/NSZS/yxz-io.git
heizhishi@LAPTOP-65FKBFN1 MINGW64 /e/java/IDEAProject/yxz-io (master)
$ git branch -M main

heizhishi@LAPTOP-65FKBFN1 MINGW64 /e/java/IDEAProject/yxz-io (main)
$ git push origin main
Logon failed, use ctrl+c to cancel basic credential prompt.
Username for 'https://github.com': 969680078@qq.com
Counting objects: 29, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (21/21), done.
Writing objects: 100% (29/29), 17.10 KiB | 648.00 KiB/s, done.
Total 29 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), done.
To https://github.com/NSZS/yxz-io.git
 * [new branch]      main -> main
heizhishi@LAPTOP-65FKBFN1 MINGW64 /e/java/IDEAProject/yxz-io (main)
$ git push origin master
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/NSZS/yxz-io.git'
heizhishi@LAPTOP-65FKBFN1 MINGW64 /e/java/IDEAProject/yxz-io (main)
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> main

heizhishi@LAPTOP-65FKBFN1 MINGW64 /e/java/IDEAProject/yxz-io (main)
$  git branch --set-upstream-to=origin/main main
Branch 'main' set up to track remote branch 'main' from 'origin'.

heizhishi@LAPTOP-65FKBFN1 MINGW64 /e/java/IDEAProject/yxz-io (main)
$ git pull
Already up to date.
heizhishi@LAPTOP-65FKBFN1 MINGW64 /e/java/IDEAProject/yxz-io (main)
$ git checkout master
error: pathspec 'master' did not match any file(s) known to git.
heizhishi@LAPTOP-65FKBFN1 MINGW64 /e/java/IDEAProject/yxz-io (main)
$ git checkout origin/main
Note: checking out 'origin/main'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at c95ad1c first commit
A       .idea/vcs.xml

heizhishi@LAPTOP-65FKBFN1 MINGW64 /e/java/IDEAProject/yxz-io ((c95ad1c...))
$ git branch -v
* (HEAD detached at origin/main) c95ad1c first commit
  main                           c95ad1c first commit

heizhishi@LAPTOP-65FKBFN1 MINGW64 /e/java/IDEAProject/yxz-io ((c95ad1c...))
$ git checkout main
Switched to branch 'main'
A       .idea/vcs.xml

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值