赞
踩
1. 查看远端分支
$ git remote -voriginhttps://github.com/yukunxie/git_test.git (fetch)originhttps://github.com/yukunxie/git_test.git (push)
2. 添加upstream分支
git remote add upstream https://github.com/yukunxie/git_test2.gitgit fetch
再次查看远端分支
git remote -voriginhttps://github.com/yukunxie/git_test.git (fetch)originhttps://github.com/yukunxie/git_test.git (push)upstreamhttps://github.com/yukunxie/git_test2.git (fetch)upstreamhttps://github.com/yukunxie/git_test2.git (push)
3. 从master分支创建新的分支
从origin/master分支创建一个新的分支develop
git checkout -b develop origin/master
查的当前的所有分支, develop是当前新创建的分支
$ git branch -a* develop master remotes/origin/master
将develop分支推送的服务器(远端)
$ git push origin developTotal 0 (delta 0), reused 0 (delta 0)remote:remote: Create a pull request for 'develop' on GitHub by visiting:remote: https://github.com/yukunxie/git_test/pull/new/developremote:To https://github.com/yukunxie/git_test.git * [new branch] develop -> develop
4. 重命名分支
将develop分支重命名为new_develop
如果已经在develop分支
$ git branch -m new_develop
如果当前一是develop分支
git branch -m develop new_develop
删除远端的旧分支,推送当前的新分支,注意:develop的冒号
$ git push origin :develop new_developTotal 0 (delta 0), reused 0 (delta 0)To https://github.com/yukunxie/git_test.git - [deleted] develop * [new branch] new_develop -> new_develop
查看分支列表
$ git branch -a master* new_develop remotes/origin/master remotes/origin/new_develop
5. 删除分支
查看帮助文档
$ git help branch git branch (-d | -D) [-r] ...OPTIONS -d, --delete 删除一个分支,该分支必须已经全部merge到它的upstream分支,或者没有upstream的话已经处于HEAD -D --delete --force的简写,强制删除
切换分支到非new_develop分支,如master分支
git checkout master
在master分支下删除new_develop分支
$ git branch -d new_developDeleted branch new_develop (was 0fa6ec5).
将删除命令推送到远端
参考命令行git push --delete
$ git push origin --delete new_developTo https://github.com/yukunxie/git_test.git - [deleted] new_develop
6. github上创建pull request
pull request是代码协作的一种,请求别人合并自己的代码,同时要求别人进行代码review,如果代码没有问题,则进行合并。
可以直接在github上发起pull request,很简单,这里不再一一说明。
7. 显示单行log
默认git log的显示内容比较多,不方便查看,可以将log聚合成一行
$ git log --pretty=oneline30b374e70e05095bd145a9cdb2a3e21cd43e00fe (HEAD -> develop, origin/develop) add some test4e2c724f742afd395dd1613c3ba9fbe25a6a9ee0 add develop test file0fa6ec5583a4b8f729c958cca0c0f69454301cc6 (upstream/master, origin/master, master) add README
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。