Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

将本地项目提交到远程仓库需要以下操作:

1. 本地提交

git init   初始化本地仓库
git add . 
git commit -m "###"      

2. 添加目标仓库地址

git remote add origin git@xx.xx.xx.xx:repos/xxx/xxx/xxx.git

3. 同步到远程仓库,先 pullpush

# 允许一些无关联的历史	
git pull origin master --allow-unrelated-histories      

git push origin 本地分支:远程分支

# 强制进行push
git push origin master -f  

修改远程仓库地址3种方式

1. 直接修改

git remote set-url origin  [url]  

# 可以添加多个仓库地址,也就意味着可以同时把代码提交到多个仓库
git remote set-url --add origin [url]

2. 先删除后修改

删除

git remote rm origin  

查看 remote url

git remote -v

3. 直接修改项目目录下.git 文件夹下config配置文件

[core]
	repositoryformatversion = 0
	filemode = false
	bare = false
	logallrefupdates = true
	symlinks = false
	ignorecase = true
[remote "origin"]
	url = git@gitee.com:username/test.git //替换为目标仓库地址
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master

常见问题

! [rejected] master -> master (fetch first) error: failed to push some refs to 'gitee.com:smallcgq/document.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

  • --force 强制提交到master分支
git push --force origin master