我是灼灼,一只初学Java的大一金渐层。
向往余秀华和狄兰·托马斯的疯狂,时常沉溺于将情感以诗相寄;追逐过王尔德、王小波的文字,后陷于毛姆和斯蒂芬·金不可自拔;热爱文学的浪潮,白日梦到底却总在现实里清醒;艳羡平静又极度渴盼奔跑的力量。
欢迎与我交流鸭· QQ:1517526827;
个人博客:https://blog.csdn.net/weixin_52777510?spm=1001.2101.3001.5343

Git推送项目到远程仓库的记录文档

提交Java项目到GitHub远程仓库的记录文档。

参考自这个博客,按照第二种方式“Git Bash Here”来做就可以啦!

嘿嘿,选它的原因是这个看起来比较简单~

GitHub–repository

1.打开Java项目所在的Java test code文件夹所在目录(不要点开哈)---->

​ 右键Java test code文件夹---->点击Git Bash Here,出现黑框框就可以敲命令啦~

2.在远程仓库的目录下面创建和小仓库一样名字的文件夹(本质是克隆)

一开始搞错了文件夹名字是瞎写的

去官网找到自己的仓库网址噢~

git clone 命令

错误示范一:

xxxxxxxxxxxxxxxxxxx MINGW64 /d/java test code
$ git clone xxxxxxxxxxxxxxxxxxx仓库网址 /Java test code

fatal: Too many arguments.

报错原因应该是这个文件夹命名的空格问题;

usage: git clone [< options >] [–] < repo > [< dir >]

-v, --verbose         be more verbose
-q, --quiet           be more quiet
--progress            force progress reporting
-n, --no-checkout     don't create a checkout
--bare                create a bare repository
--mirror              create a mirror repository (implies bare)
-l, --local           to clone from a local repository
--no-hardlinks        don't use local hardlinks, always copy
-s, --shared          setup as shared repository
--recursive ...       alias of --recurse-submodules
--recurse-submodules[=<pathspec>]
                      initialize submodules in the clone
-j, --jobs <n>        number of submodules cloned in parallel
--template <template-directory>
                      directory from which templates will be used
--reference <repo>    reference repository
--reference-if-able <repo>
                      reference repository
--dissociate          use --reference only while cloning
-o, --origin <name>   use <name> instead of 'origin' to track upstream
-b, --branch <branch>
                      checkout <branch> instead of the remote's HEAD
-u, --upload-pack <path>
                      path to git-upload-pack on the remote
--depth <depth>       create a shallow clone of that depth
--shallow-since <time>
                      create a shallow clone since a specific time
--shallow-exclude <revision>
                      deepen history of shallow clone, excluding rev
--single-branch       clone only one branch, HEAD or --branch
--no-tags             don't clone any tags, and make later fetches not to follow them
--shallow-submodules  any cloned submodules will be shallow
--separate-git-dir <gitdir>
                      separate git dir from working tree
-c, --config <key=value>
                      set config inside the new repository
--server-option <server-specific>
                      option to transmit
-4, --ipv4            use IPv4 addresses only
-6, --ipv6            use IPv6 addresses only
--filter <args>       object filtering
错误示范二:

换个文件夹名字敲敲看:

xxxxxxxxxxxxxxxxxxx MINGW64 /d/java test code
$ git clone xxxxxxxxxxxxxxxxxxx 仓库网址/code
Cloning into ‘code’…
remote: Not Found
fatal: repository 'xxxxxxxxxxxxxxxxxxx ’ not found

找不到我的仓库?

可能是网址错了,这个是从网站上面的克隆那里复制过来的,可能是https的问题?

错误示范三:

换成ssh试一下!

xxxxxxxxxxxxxxxxxxx MINGW64 /d/java test code
$ git clone xxxxxxxxxxxxxxxxxxx 仓库网址/code
Cloning into ‘code’…
The authenticity of host ‘xxxxxxxxxxxxxxxxxxx ip’ can’t be established.
xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx .
Are you sure you want to continue connecting (yes/no/[fingerprint])? y
Please type ‘yes’, ‘no’ or the fingerprint: yes
Warning: Permanently added 'xxxxxxxxxxxxxxxxxxx ip to the list of known hosts.
fatal: remote error:
xxxxxxxxxxxxxxxxxxx /code is not a valid repository name
Visit https://support.github.com/ for help

报错了…翻译一下:

xxxxxxxxxxxxxxxxxxx MINGW64 / d / java测试代码

$ git clone xxxxxxxxxxxxxxxxxxx 仓库网址 / code

克隆为“代码” …

无法确定主机“ xxxxxxxxxxxxxxxxxxx ip”的真实性。

xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx 。

您确定要继续连接(是/否/ [指纹])吗?
ÿ

请输入“是”,“否”或指纹:是

警告:将“ xxxxxxxxxxxxxxxxxxx ip永久添加到已知主机列表中。

致命:远程错误:

仓库名称 / code不是有效的存储库名称

请访问https://support.github.com/以获得帮助

是仓库错了?

错误示范四:

换成仓库页面的链接试试:

xxxxxxxxxxxxxxxxxxxMINGW64 /d/java test code
$ git clone /code
Cloning into ‘code’…
remote: Not Found
fatal: repository ‘xxxxxxxxxxxxxxxxxxx仓库网址/code/’ not found

报错找不到仓库?呃…

好吧,理解错教程的意思了,最后写的那是仓库的名字…再试!

正确示范五!!!:

xxxxxxxxxxxxxxxxxxx MINGW64 /d/java test code
$ git clone xxxxxxxxxxxxxxxxxxx仓库网址/learngit
Cloning into ‘learngit’…
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.

翻译一下:

xxxxxxxxxxxxxxxxxxx MINGW64 / d / java测试代码

$ git clone xxxxxxxxxxxxxxxxxxx仓库网址/learngit

克隆到“ learngit”中…

远程:枚举对象:3,完成。

远程:计数对象:100%(3/3),已完成。

远程:压缩对象:100%(2/2),已完成。

远程:总计3(增量0),已重用3(增量0),已重用包0

拆箱:完成100%(3/3)。

3.移动除learngit以外的文件到learngit,手动剪切CTRL+x粘贴CTRL+v;
4.打开小仓库文件夹

cd命令

xxxxxxxxxxxxxxxxxxx MINGW64 /d/java test code
$ cd learngit

5.添加文件到仓库

git add .命令(注意.前面有个空格)

xxxxxxxxxxxxxxxxxxx MINGW64 /d/java test code/learngit (main)
$ git add .

警告:

warning: LF will be replaced by CRLF in .xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xml.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in .xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in .xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxml.
The file will have its original line endings in your working directory

翻译:

警告:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xml中的LF将由CRLF替换。

该文件将在您的工作目录中具有其原始行结尾

警告:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxixxxxxxxxxxxxxxxxxxx中的LF将由CRLF替换。

该文件将在您的工作目录中具有其原始行结尾

警告:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xml中的LF将被CRLF替换。

该文件将在您的工作目录中具有其原始行结尾

呃,真叫人摸不着头脑,查一下!

解决的博客

这个,本来想修改一下这个警告的,但是,粘贴错了=_=

=_=呃,直接给我提交了(!!!!完蛋);

6.提交文件到仓库

git commit -m "first commit"命令(引号里面是提交说明)

xxxxxxxxxxxxxxxxxxx MINGW64 /d/java test code/learngit (main)
$ git commit -m “first commit”
[main a789d64] first commit
38 files changed, 2562 insertions(+)
create mode 100644 .ixxxxxxxxxxxxxxxxxxx
create mode 100644 .xxxxxxxxxxxxxxxxxxx
create mode 100644 .xxxxxxxxxxxxxxxxxxx
create mode 100644 .xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
create mode 100644 .xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
create mode 100644 .ixxxxxxxxxxxxxxxxxxx
create mode 100644 .xxxxxxxxxxxxxxxxxxx
此处省略一大堆

7.推送文件到远程仓库:

git push -u origin main(远程仓库名字简写或引用叫origin,远程仓库默认分支叫main)

xxxxxxxxxxxxxxxxxxx MINGW64 /d/java test code/learngit (main)
$ git push -u origin main
Logon failed, use ctrl+c to cancel basic credential prompt.

弹出窗口输入用户名和密码:

-----不出意外,又显示是错的;

再次弹出输入用户名,完成点击ok;

再次弹出输入密码,完成点击ok;

现在就推送啦~

Enumerating objects: 65, done.
Counting objects: 100% (65/65), done.
Delta compression using up to 8 threads
Compressing objects: 100% (53/53), done.
Writing objects: 100% (64/64), 2.20 MiB | 55.00 KiB/s, done.
Total 64 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx仓库网址
xxxxxxxxxxxxxxxxxxx main -> main
Branch ‘main’ set up to track remote branch ‘main’ from ‘origin’.

8.推送完成!到GitHub官网去瞅瞅~

文件已经来啦!

交作业的时候发现提交错了,应该是推送到码云…
可怜的我流下了不争气的泪水…再来一次!

Gitee–repository

<!-Gitee提交Java项目到远程仓库的记录文档–>

创建仓库及连接参考自廖雪峰官方教程~

关联远程仓库

xxxxxxxxxxxxxxxxxxx MINGW64 ~ (master)
$ git remote add origin xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx仓库网址

检查是否关联其它远程库

xxxxxxxxxxxxxxxxxxx MINGW64 ~ (master)
$ git remote -v
origin xxxxxxxxxxxxxxxxxxx仓库网址 (fetch)
origin xxxxxxxxxxxxxxxxxxx仓库网址 (push)

啊这,难道没有和我的GitHub关联???

不知道了,刚刚还推送了文件=_=我的头呢?

他可能是自己改掉了,把GitHub上origin的脑袋直接摘下来安在了gitee的头上,我手动改一下,把两个仓库都连上吧!

这,粘贴错误导致的惨剧…

xxxxxxxxxxxxxxxxxxx MINGW64 ~ (master)
$ git remote rm origin

xxxxxxxxxxxxxxxxxxx MINGW64 ~ (master)
$ git remote add github tps://xxxxxxxxxxxxxxxxxxx仓库网址

xxxxxxxxxxxxxxxxxxx MINGW64 ~ (master)

$ git remote add github xxxxxxxxxxxxxxxxxxx仓库网址
fatal: remote github already exists.

再来一次!

xxxxxxxxxxxxxxxxxxx MINGW64 ~ (master)
$ git remote rm github

xxxxxxxxxxxxxxxxxxx MINGW64 ~ (master)
$ git remote add github xxxxxxxxxxxxxxxxxxx仓库网址

xxxxxxxxxxxxxxxxxxx MINGW64 ~ (master)
$ git remote add gitee xxxxxxxxxxxxxxxxxxx仓库网址

xxxxxxxxxxxxxxxxxxx MINGW64 ~ (master)
$ git remote -v
gitee xxxxxxxxxxxxxxxxxxxgitee仓库网址 (fetch)
gitee xxxxxxxxxxxxxxxxxxxgitee仓库网址 (push)
github xxxxxxxxxxxxxxxxxxxGitHub仓库网址 (fetch)
github xxxxxxxxxxxxxxxxxxxGitHub仓库网址(push)

以后呢!如果要推送到GitHub,使用命令:

git push github master

如果要推送到Gitee,使用命令:

git push gitee master

我们把之前推送的流程再走一遍…

因为都是用git实现的,所以应该是一样的吧?

首先把原来的文件恢复过来,之前被移动了~

1.打开Java项目所在的Java test code文件夹所在目录(不要点开哈)---->

​ 右键Java test code文件夹---->点击Git Bash Here,出现黑框框就可以敲命令啦~

2.在远程仓库的目录下面创建和小仓库一样名字的文件夹(本质是克隆)

去官网找到自己的仓库网址噢~

git clone 命令

原来第二次弄也还是会出错啊!

错误示范一:

忘记了克隆目录是在用户名下面,然后创建的文件夹名字叫learngit…

因为仓库也叫这个

xxxxxxxxxxxxxxxxxxx MINGW64 /d/java test code
$ git clone xxxxxxxxxxxxxxxxxxx仓库网址
Cloning into ‘learngit’…
warning: You appear to have cloned an empty repository.

翻译:

xxxxxxxxxxxxxxxxxxx MINGW64 /d/java test code
$ git clone xxxxxxxxxxxxxxxxxxx仓库网址
Cloning into ‘learngit’…
warning: You appear to have cloned an empty repository.

其实没什么区别,这个空仓库是什么意思,不可以这样?警告应该没什么问题吧,查询一下!

这个可以不用管,因为真的是个空仓库。。。。

3.移动除learngit以外的文件到learngit,手动剪切CTRL+x粘贴CTRL+v;
4.打开小仓库文件夹

cd命令

xxxxxxxxxxxxxxxxxxx MINGW64 /d/java test code
$ cd learngit

5.添加文件到仓库(一模一样哒,连警告都一样~)

git add .命令(注意.前面有个空格)

xxxxxxxxxxxxxxxxxxx MINGW64 /d/java test code/learngit (main)
$ git add .

警告:

warning: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

翻译:

警告:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xml中的LF将由CRLF替换。

该文件将在您的工作目录中具有其原始行结尾

警告:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxixxxxxxxxxxxxxxxxxxx中的LF将由CRLF替换。

该文件将在您的工作目录中具有其原始行结尾

警告:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xml中的LF将被CRLF替换。

该文件将在您的工作目录中具有其原始行结尾

6.提交文件到仓库

git commit -m "first commit"命令(引号里面是提交说明)

xxxxxxxxxxxxxxxxxxxxx MINGW64 /d/java test code/learngit (master)
$ git commit -m “first commit”
[master (root-commit) 23998ae] first commit
38 files changed, 2562 insertions(+)
create mode 100644 .xxxxxxxxxxxxxxxxxxxxx
create mode 100644 .xxxxxxxxxxxxxxxxxxxxx
create mode 100644 .xxxxxxxxxxxxxxxxxxxxx
create mode 100644 .xxxxxxxxxxxxxxxxxxxxx
create mode 100644 .xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
create mode 100644 .xxxxxxxxxxxxxxxxxxxxx
此处省略一万字…

7.推送文件到远程仓库:

这里注意先初始化一个readme文件,不然好像没有默认分支。

git push -u gitee master(远程仓库名字简写或引用叫gitee,远程仓库默认分支叫master)

又报错了!

xxxxxxxxxxxxxxxxxxxxx MINGW64 /d/java test code/learngit (master)
$ git push -u gitee master
fatal: ‘gitee’ does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

翻译:

xxxxxxxxxxxxxxxxxxxxx MINGW64 / d / java测试代码/ learngit(master)

$ git push -u gitee主

致命:'gitee’似乎不是git存储库

致命:无法从远程存储库读取。

请确保您具有正确的访问权限

并且存储库存在。

应该把gitee改成learngit吧,试一下!

xxxxxxxxxxxxxxxxxxxxx MINGW64 /d/java test code/learngit (master)
$ git push -u learngit master
fatal: ‘learngit’ does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

可能还是叫origin?再试一下!

竟然可以了!弹出窗口输入用户名和密码:

又报错了哈哈~

xxxxxxxxxxxxxxxxxxxxx MINGW64 /d/java test code/learngit (master)
$ git push -u origin master
To xxxxxxxxxxxxxxxxxxxxx仓库网址
! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘xxxxxxxxxxxxxxxxxxxxx仓库网址’
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.

翻译:

xxxxxxxxxxxxxxxxxxxxx MINGW64 / d / java测试代码/ learngit(master)

$ git push -u原始主机

到xxxxxxxxxxxxxxxxxxxxx仓库网址


[拒绝]管理员->管理员(先获取)

错误:无法将某些引用推送到“ xxxxxxxxxxxxxxxxxxxxx仓库网址”

提示:更新被拒绝,因为远程包含您所做的工作

提示:本地没有。
这通常是由另一个存储库推送引起的

提示:相同的参考。
您可能需要先集成远程更改

提示:(例如’git pull …’),然后再次按下。

提示:有关详细信息,请参见“ git push --help”中的“关于快进的注意事项”。

解决办法,参考百度

xxxxxxxxxxxxxxxxxxxxx MINGW64 /d/java test code/learngit (master)
$ git pull --rebase origin master
warning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From xxxxxxxxxxxxxxxxxxxxx仓库网址

  • branch master -> FETCH_HEAD
  • [new branch] master -> origin/master
    First, rewinding head to replay your work on top of it…
    Applying: first commit
8.再次执行推送命令:

xxxxxxxxxxxxxxxxxxxxx MINGW64 /d/java test code/learngit (master)
$ git push -u origin master
Enumerating objects: 65, done.
Counting objects: 100% (65/65), done.
Delta compression using up to 8 threads
Compressing objects: 100% (53/53), done.
Writing objects: 100% (64/64), 2.20 MiB | 67.00 KiB/s, done.
Total 64 (delta 1), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-5.0]
To xxxxxxxxxxxxxxxxxxxxx仓库网址
702ce46…7d043df master -> master
Branch ‘master’ set up to track remote branch ‘master’ from ‘origin’.

这里就推送完成啦~

9.推送完成!到gitee官网去瞅瞅~

文件已经来啦!

终于搞完了,嘿嘿!

在这里插入图片描述

如果对你有帮助的话不要忘记一键三连噢~
谢谢鸭~

初次编写于2021/1/29日;

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐