GIT常用命令

纵饮孤独 提交于 2019-12-03 08:09:34

 

文档:git命令.note
链接:http://note.youdao.com/noteshare?id=ac0dafda7ca22096fc27b49541db474b&sub=BB2AB91B4A6740E6800FD66AA1455B480本地代码提交到远程仓库:
设置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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!