下载github代码git
git clone https://github.com/zhoug2020/2015.gitgithub
在github上建立仓库:
Create a new repository on the command line
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/BrentHuang/MyRepo.git
git push -u origin master
在本地新建一个分支: git branch Branch1
切换到你的新分支: git checkout Branch1
将新分支发布在github上: git push origin Branch1
在本地删除一个分支: git branch -d Branch1
在github远程端删除一个分支: git push origin :Branch1 (分支名前的冒号表明删除)
直接使用git pull和git push的设置
git branch --set-upstream-to=origin/master master
git branch --set-upstream-to=origin/ThirdParty ThirdParty
git config --global push.default matching网站
新建好的代码库有且仅有一个主分支(master),它是自动创建的。
能够新建分支用于开发:
git branch develop master
新建一个叫develop的分支,基于master分支spa
切换到这个分支:
git checkout develop
如今能够在这个develop分支上作一些改动,而且提交。
注意:切换分支的时候能够发现,在Windows中的repository文件夹中的文件内容也会实时相应改变,变成当前分支的内容。开发
push方法1:rem
如今若是想直接Push这个develop分支上的内容到githubit
git push -u originast
若是是新建分支第一次push,会提示:
fatal: The current branch develop has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin develop
输入这行命令,而后输入用户名和密码,就push成功了。class
之后的push就只须要输入git push originstream
push方法2:
好比新建了一个叫dev的分支,而github网站上尚未,能够直接:
git push -u origin dev
这样一个新分支就建立好了。
push方法3:
提交到github的分支有多个,提交时能够用这样的格式:
git push -u origin local:remote
好比:git push -u origin master:master
代表将本地的master分支(冒号前)push到github的master分支(冒号后)。
若是左边不写为空,将会删除远程的右边分支。
用命令git checkout -b develop2 develop
能够新建一个分支develop2,同时切换到这个分支
git branch能够查看全部的分支
git branch -d develop2 将develop2分支删除
使用git clone+github地址的方法,项目默认只有master分支。git branch也只有master
要看全部的分支:git branch -a或者是git branch -r
这时候要新建一个分支,叫作dev,基于远程的dev分支:git checkout -b dev origin/dev
git tag tagname develop
git tag中的两个参数,一个是标签名称,另外一个是但愿打标签的点develop分支的末梢。
git checkout master
先转到主分支
git merge --no-ff develop
而后把develop分支merge过来
参数意义:
不用参数的默认状况下,是执行快进式合并。
使用参数--no-ff,会执行正常合并,在master分支上生成一个新节点。
merge的时候若是遇到冲突,就手动解决,而后从新add,commit便可。