1在码云新建项目
2本地新建项目,包括readme.md,ignore这俩个文件
初始化仓库
git init
关联远程仓库
git remote add origin git@github.com:YotrolZ/helloTest.git
git add *
git commit —m"初次提交"
E:\mm\zdh>git push -u origin master------------我们第一次push
的时候,加上-u
参数,Git就会把本地的master分支和远程的master分支进行关联起来,我们以后的push
操作就不再需要加上-u
参数了
To https://gitee.com/antims/zdh.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/antims/zdh.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.
E:\mm\zdh>git pull origin master
warning: no common commits
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
From https://gitee.com/antims/zdh
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
fatal: refusing to merge unrelated histories
E:\mm\zdh>git push -u origin master-------------------不可以
To https://gitee.com/antims/zdh.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/antims/zdh.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.
E:\mm\zdh>git push -u -f origin master----------------------注释:-f是强制推送,覆盖远程
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (5/5), 316 bytes | 0 bytes/s, done.
Total 5 (delta 0), reused 0 (delta 0)
To https://gitee.com/antims/zdh.git
+ b9d4e84...fb730f5 master -> master (forced update)
Branch master set up to track remote branch master from origin.
总计操作如下即可:
2本地新建项目,包括readme.md,ignore这俩个文件
初始化仓库
git init
关联远程仓库
git remote add origin git@github.com:YotrolZ/helloTest.git
git add *
git commit —m"初次提交"
git pull origin master
git push -u -f origin master