本地项目添加远程GIT管理

  1. git init

  2. git add .

  3. git commit -m “init”

  4. git remote add origin 你的github仓库地址

  5. git push

但是,以上步骤,可能会出错,如下:

$ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master

执行红色部分:

$ git push --set-upstream origin master
To gitee.com:xxxxx/yyyyy.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to '[email protected]:xxxxx/yyyyy.git'
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.

还是报错

在push远程服务器的时候发现出现此错误;原因是没有同步远程的master

所以我们需要先同步一下,使用git pull origin master

$ git pull origin master
warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From gitee.com:xxxxx/yyyyy.git
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
fatal: refusing to merge unrelated histories

依然有错误,接下来只要如下设置一下就OK了

$ git pull origin master --allow-unrelated-histories
From gitee.com:xxxxx/yyyyy.git
 * branch            master     -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 README.md | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 README.md

然后,继续同步操作:

$ git pull origin master
From gitee.com:xxxxx/yyyyy.git
 * branch            master     -> FETCH_HEAD
Already up-to-date.

再来设置一下upstream

$ git push --set-upstream origin master
Counting objects: 44, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (35/35), done.
Writing objects: 100% (44/44), 53.92 KiB | 0 bytes/s, done.
Total 44 (delta 2), reused 0 (delta 0)
To gitee.com:xxxxx/yyyyy.git
   1e4dc19..8d8694c  master -> master
Branch master set up to track remote branch master from origin.
如上操作,就可以了










猜你喜欢

转载自blog.csdn.net/cin_ie/article/details/79558153