git上传

今天上传项目到git的时候遇到一个很让人头疼的问题

首先上传到gitee的步骤和网上大部分撸友差不多一致
登录gitee新建项目
本地新建项目(最好和本地保持一致)
之后使用命令:
git remote add origin 码云pull地址将本地仓库项目与远程仓库项目进行关联

重点来了
使用以上命令后,是成功了,但是我在码云上并没有看到我关联后的代码
明明成功了,为什么没看到呢?
于是我又执行了一遍关联的命令,这个时候他提醒我:
fatal: remote origin already exists.
事实上,它确实是关联上了,然后我想试试推我本地代码,使用命令git push -u origin master,不出意外的,报错了:error: src refspec master does not match any.
没有任何匹配的,则push报错

于是我想拉一下看看(git pull -rebase origin master),又是一大段:

  error: Invalid value for --rebase: ebase
usage: git pull [] [ [...]]

    -v, --verbose         be more verbose
    -q, --quiet           be more quiet
    --progress            force progress reporting
    --recurse-submodules[=]
                          control for recursive fetching of submodules

Options related to merging
    -r, --rebase[=]
                          incorporate changes by rebasing rather than merging
    -n                    do not show a diffstat at the end of the merge
    --stat                show a diffstat at the end of the merge
    --log[=]           add (at most ) entries from shortlog to merge commit message
    --signoff[=...]       add Signed-off-by:
    --squash              create a single commit instead of doing a merge
    --commit              perform a commit if the merge succeeds (default)
    --edit                edit message before committing
    --ff                  allow fast-forward
    --ff-only             abort if fast-forward is not possible
    --verify-signatures   verify that the named commit has a valid GPG signature
    --autostash           automatically stash/stash pop before and after rebase
    -s, --strategy 
                          merge strategy to use
    -X, --strategy-option 
                          option for selected merge strategy
    -S, --gpg-sign[=]
                          GPG sign commit
    --allow-unrelated-histories
                          allow merging unrelated histories

Options related to fetching
    --all                 fetch from all remotes
    -a, --append          append to .git/FETCH_HEAD instead of overwriting
    --upload-pack   path to upload pack on remote end
    -f, --force           force overwrite of local branch
    -t, --tags            fetch all tags and associated objects
    -p, --prune           prune remote-tracking branches no longer on remote
    -j, --jobs[=]      number of submodules pulled in parallel
    --dry-run             dry run
    -k, --keep            keep downloaded pack
    --depth        deepen history of shallow clone
    --unshallow           convert to a complete repository
    --update-shallow      accept refs that update .git/shallow
    --refmap      specify fetch refmap
    -4, --ipv4            use IPv4 addresses only
    -6, --ipv6            use IPv6 addresses only

瞬间感觉头大了,,
查看远程连接$ git remote -v,也没错哇,接着git init,依旧没卵用

后来万能的百度让我发现了问题所在
可能很多人同一个项目会同时上传到码云和github,而仓库都是同一个本地仓库 ,这个时候就会有问题了,因为她俩默认的远程仓库地址都是origin,问题就出在这,它不知道是哪个了。
于是乎
git remote rm origin - 先删除远程分支
git remote add gitee-origin 码云 - 重新添加关联远程分支,注意,这个时候add 的时候使用新的远程分支名称gitee-origin,而不是默认的origin
之后点pull,后push
pull的时候可能因为前面如果你本地和远程名称使用不一致造成的pull失败,则使用如下命令:
正常:$ git pull gitee-origin master
名称不一致(远程与本地仓库):$ git pull gitee-origin master --allow-unrelated-histories
接着
$ git push gitee-origin master

Counting objects: 106, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (60/60), done.
Writing objects: 100% (106/106), 11.30 KiB | 340.00 KiB/s, done.
Total 106 (delta 17), reused 0 (delta 0)
remote: Resolving deltas: 100% (17/17), done.
remote: Powered by Gitee.com
To https://gitee.com/wxbPersonal/personal-boot.git
   40d1a07..ea93f8e  master -> master

终于成功了,,

你可能感兴趣的:(git上传)