本地代码提交到远程仓库:
设置git用户名、邮箱
git config --global user.name xxx git用户名git config --global user.email xxx git邮箱
将项目提交到主分支(master):
git remote rm origin 删除现有远程连接git init 初始化本地仓库touch README.md 创建README.md文件git add . 将修改的文件添加到暂存git commit -m "first commit" 将暂存中的文件提交到本地当前分支git remote add origin https://xxxxxxx.xx/xx/ 将本地仓库连接到远程仓库git push -u origin master 将本地仓库文件push到远程master分支
将主分支代码pull到dev分支:
git branch -a 查看远程全部分支git checkout -b dev origin/dev 在本地创建dev分支并将远程dev分支更新到本地分支git pull origin master --allow-unrelated-histories 将master分支强制更新到当前分支(执行git pull origin master 抛出错误refusing to merge unrelated histories)
错误解决:
命令:git push origin masterfailed to push some refs to 'https://github.com/CrazyDony/text.git'hint: Updates were rejected because the tip of your current branch is behindhint: 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-fCounting objects: 35, done.Delta compression using up to 4 threads.Compressing objects: 100% (29/29), done.Writing objects: 100% (35/35), 10.15 KiB | 0 bytes/s, done.Total 35 (delta 5), reused 0 (delta 0)To https://github.com/CrazyDony/text.git+ aa70966...f64b22a master -> master (forced update)Branch master set up to track remote branch master from origin. 完成
本地新建分支,并上传到云端新分支:
假设当前分支为master,需要创建的分支是dev
1 git checkout -b dev //在当前分支下创建dev的本地分支分支 2 git push origin dev //将dev分支推送到远程 3 git branch --set-upstream-to=origin/dev //将本地分支dev关联到远程分支dev上 4 git branch -a //查看远程分支
此时远程分支dev已经创建好了,并且本地的分支已经关联到远程分支上
本地push代码以后会push到关联的远程分支上。
分支合并:
将dev分支合并到master分支:
git checkout mastergit merge dev