git push 时遇到的问题 REJECTED

本文主要参考:http://www.07net01.com/2015/11/1000704.html 得以解决问题

一、使用git在本地创建一个项目的过程
    首先得在github或者git@OSC上创建一个hello-world项目。本地才能进行推送
    $ makdir ~/hello-world    //创建一个项目hello-world
    $ cd ~/hello-world       //打开这个项目
    $ git init             //初始化 
    $ touch README
    $ git add README        //更新README文件
    $ git commit -m 'first commit'     //提交更新,并注释信息“first commit” 
    $ git remote add origin git@github.com:defnngj/hello-world.git     //连接远程github项目  当然 origin还可以 origin_new
    $ git push -u origin master     //将本地项目更新到github项目上去   

    执行:git push -u origin master -f 以及 git push origin master  
二、其他常用命令:
git remote -v  //查看地址
git config --list  //查看配置
git status  //查看状态
git remote rm origin  //删除origin这个push地址
rm -rf  ~/.ssh  删除.ssh 文件和文件夹
rm -f ~/.ssh 删除文件
    
三、git push遇到的问题:
本来想用 ssh传输的,结果用ssh传输总是报错:

Administrator@PC201611290918 MINGW64 /d/Git@OSC/SpringMVC (master)
$ git remote add origin git@git.oschina.net:MaGary/SpringMVC.git

Administrator@PC201611290918 MINGW64 /d/Git@OSC/SpringMVC (master)
$ git push -u origin master
Access denied.
fatal: Could not read from remote repository.

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

Administrator@PC201611290918 MINGW64 /d/Git@OSC/SpringMVC (master)
$ git pull
Access denied.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights

先在gitHUb或则Git@OSC上创建项目。后来我改用 https地址提交项目:
https://git.oschina.net/MaGary/SpringMVC.git/

重新设置remote地址: git remote add origin https://git.oschina.net/MaGary/SpringMVC.git

接着进行 push操作:结果报错:(git push -u origin master 以及 git push  origin master)度有错:都是:![rejected]  master -> master(fetch first);  ![rejected]  master -> master(non-fast-forward); 

Administrator@PC201611290918 MINGW64 /d/Git@OSC/SpringMVC (master)
$ git push -u origin master
Username for 'https://git.oschina.net': fshengbing0327@163.com
To https://git.oschina.net/MaGary/SpringMVC.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://git.oschina.net/MaGary/SpringMVC.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.

Administrator@PC201611290918 MINGW64 /d/Git@OSC/SpringMVC (master)
$ git push origin master
Username for 'https://git.oschina.net': fshengbing0327@163.com
To https://git.oschina.net/MaGary/SpringMVC.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://git.oschina.net/MaGary/SpringMVC.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

解决办法:

执行:git push -u origin master -f 以及 git push origin master

Administrator@PC201611290918 MINGW64 /d/Git@OSC/SpringMVC (master)
$ git push -u origin master -f
Username for 'https://git.oschina.net': fshengbing0327@163.com
Counting objects: 253, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (204/204), done.
Writing objects: 100% (253/253), 7.63 MiB | 1.43 MiB/s, done.
Total 253 (delta 74), reused 0 (delta 0)
remote: Resolving deltas: 100% (74/74), done.
To https://git.oschina.net/MaGary/SpringMVC.git
 + 8cdf4d4...d7e93f6 master -> master (forced update)
Branch master set up to track remote branch master from origin.

Administrator@PC201611290918 MINGW64 /d/Git@OSC/SpringMVC (master)
$ git push origin master
Username for 'https://git.oschina.net': fshengbing0327@163.com
Everything up-to-date

 

转载于:https://my.oschina.net/u/2359764/blog/810989

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值