码迷,mamicode.com
首页 > 其他好文 > 详细

git项目提交及分支操作命令

时间:2019-11-05 18:37:29      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:--   初始化   hub   git init   git merge   commit   use   用户名   --help   

本地代码提交到远程仓库:

设置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 master
        failed to push some refs to ‘https://github.com/CrazyDony/text.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
        Counting 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. 完成

分支合并:

将dev分支合并到master分支:

git  checkout master
git merge dev

git项目提交及分支操作命令

标签:--   初始化   hub   git init   git merge   commit   use   用户名   --help   

原文地址:https://www.cnblogs.com/XYYCKL/p/11800108.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!