GitHub常用命令工作中的使用
2017-03-22 14:52
225 查看
0、克隆分支
git clone <url> -b <分支名称> --depth 1 eg. git clone https://xxx.git -b master ##clone Tag git clone -b '3.28.0.20170327' --single-branch --depth 1 https://github.com/huifenqi/payment-2.0.git[/code]1、git push命令用于将本地分支的更新,推送到远程主机
git push <远程主机名> <本地分支名>:<远程分支名>
参考地址:http://www.yiibai.com/git/git_push.html2、为了便于管理,Git要求每个远程主机都必须指定一个主机名。git remote命令就用于管理主机名。
$ git remote ##列出所有远程主机 $ git remote -v ##使用-v选项,可以参看远程主机的网址。 $ git remote show <主机名> ##可以查看该主机的详细信息。 $ git remote add <主机名> <网址> ##命令用于添加远程主机
参考地址:http://www.yiibai.com/git/git_remote.html2-1 Git使用Tag
$ git tag #查看 $ git tag <tag_name> #eg. git tag v1.1 $ git push origin --tags # 推送线上 $ git push origin :refs/tags/<标签名> ##删除远程标签 $ git tag -d <标签名> ##删除本地标签3、分支管理
git branch new_branch ##创建分支 git checkout new_branch ##切换分支 git checkout -b test_branch ##创建和切换分支的快捷方式 git branch -D test_branch ##删除分支 git branch -m new_branch wchar_support ##重命名分支 git merge origin/wchar_support ##合并两个分支(在 master上操作此时合并到master分支上) #设置分支跟踪远程分支 $ git branch -u origin/master Branch master set up to track remote branch master from origin. ##重订分支 ######################### Git 的 rebase命令的一个分支合并的命令,但不同的是,它修改提交的顺序 Git merge命令,试图把从其他分支提交当前的本地分支的HEAD上。例如 本地的分支已经提交A-> B-> C-> D和合并分支已提交A-> B-> X> Y, 则Git合并将当前转换像这样的本地分行A-> B-> C-> D-> X-> Y Git 的rebase命令试图找到当前的本地分支和合并分支之间的共同祖先。 然后把修改提交的顺序,在当前的本地分支提交中的本地分支。 例如,如果当地的分支已提交A-> B-> C-> D和合并分支已提交A-> B-> X-> Y, Git衍合的类似A-> B转换成当前的本地分支A−>B−>X−>Y−>C−>D 当多个开发人员在一个单一的远程资源库的工作,你不能在远程仓库提交修改订单。 在这种情况下,可以使用变基操作把本地提交的远程仓库之上的提交,可以推送这些变化。 #########################
参考地址: http://www.yiibai.com/git/git_managing_branches.html4、其他命令
git status -s ##以精简的方式显示文件状态 ########################### A:新文件第一次被添加进版本管理 M:红色为修改过未被添加进暂存区的,绿色为已经添加进暂存区的 ########################### git diff <file> ##比较修改的不同之处 git log -1 ##(参数是 横杠数字1) git show <commit id> ##审核查看变化 git branch -a ##查看所有的分支,包括远程分支5、修改远程仓库地址
git remote set-url origin http://www.cnblogs.com/merray/p/5698331.html" target=_blank>
eg. git remote set-url origin https://xxx.git $ git remote set-url origin https://github.com/hfq-shimanqiang/payment-2.0.git [/code]
参考地址:[url=http://www.cnblogs.com/merray/p/5698331.html]http://www.cnblogs.com/merray/p/5698331.html
参考地址中,最后一条 命令顺序不正确啊!!看我的
参考地址2 : [url=http://blog.csdn.net/u013260551/article/details/51317777]http://blog.csdn.net/u013260551/article/details/513177776-0、GitHub pull requests说明
base fork 是你将要pull requests的上游仓库 head fork 是新模块或者新特性分支仓库6-1、如何同步 Github fork 出来的分支,跟踪上游仓库变化
##添加并指向上游仓库 'git remote add upstream <上游仓库的地址>' eg. git remote add upstream https://github.com/huifenqi/payment-2.0.git ################################# $ git remote -v origin https://github.com/hfq-shimanqiang/payment-2.0.git (fetch) origin https://github.com/hfq-shimanqiang/payment-2.0.git (push) $ git remote add upstream https://github.com/huifenqi/payment-2.0.git $ git remote -v origin https://github.com/hfq-shimanqiang/payment-2.0.git (fetch) origin https://github.com/hfq-shimanqiang/payment-2.0.git (push) upstream https://github.com/huifenqi/payment-2.0.git (fetch) upstream https://github.com/huifenqi/payment-2.0.git (push) ################################## ##从上游仓库 fetch 分支和提交点,传送到本地,并会被存储在一个本地分支 upstream/master 'git fetch upstream' ################################## $ git fetch upstream From https://github.com/huifenqi/payment-2.0 * [new branch] 2017031001 -> upstream/2017031001 * [new branch] 20170321 -> upstream/20170321 * [new branch] master -> upstream/master $ git branch -a * 2017031001 20170321 develop master remotes/origin/20170321 remotes/origin/HEAD -> origin/master remotes/origin/master remotes/upstream/2017031001 remotes/upstream/20170321 remotes/upstream/master ################################# ##切换到本地分支master,合并代码 'git checkout master' 'git merge upstream/master' ##如果想更新到 GitHub 的 fork 上, 直接 'git push origin master' 就好了
参考地址:https://gaohaoyang.github.io/2015/04/12/Syncing-a-fork/
参考地址:http://jinlong.github.io/2015/10/12/syncing-a-fork/6-2、git远程删除分支后,本地git branch -a 依然能看到的解决办法
git remote show origin,可以查看remote地址,远程分支,还有本地分支与之相对应关系等信息 根据提示,使用 git remote prune origin 命令 $ git remote prune origin
参考地址:http://blog.csdn.net/qq_16885135/article/details/527778717、使用操作(8)之后:命令总结
#从远程分支checkout并且跟踪 $ git checkout --track remotes/origin/2017031001 #删除远程分支,本地分支删除git branch -D <barnch_name> $ git push origin --delete 20170310018、使用操作
###########展示origin主机的信息################ $ git remote show origin * remote origin Fetch URL: https://github.com/hfq-shimanqiang/payment-2.0.git Push URL: https://github.com/hfq-shimanqiang/payment-2.0.git HEAD branch: master Remote branches: 2017031001 tracked 20170321 tracked master tracked Local branch configured for 'git pull': master merges with remote master Local refs configured for 'git push': 20170321 pushes to 20170321 (up to date) master pushes to master (up to date) ###########查看具体的远程分支############# $ git branch -a * 20170321 develop master remotes/origin/2017031001 remotes/origin/20170321 remotes/origin/HEAD -> origin/master remotes/origin/master ##########删除远程分支################竟然发生了错误??why $ git push origin --delete remotes/origin/2017031001 error: unable to delete 'remotes/origin/2017031001': remote ref does not exist error: failed to push some refs to 'https://github.com/hfq-shimanqiang/payment-2.0.git' ####继续操作 $ git branch -r origin/2017031001 origin/20170321 origin/HEAD -> origin/master origin/master ######难道是因为本地和github上不一致吗? $ git pull There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details. git pull <remote> <branch> If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/<branch> 20170321 ###按照提示执行一下###不行啊? $ git branch --set-upstream-to=origin/master master Branch master set up to track remote branch master from origin. ###继续# $ git checkout --track remotes/origin/2017031001 Switched to a new branch '2017031001' Branch 2017031001 set up to track remote branch 2017031001 from origin. $ git branch * 2017031001 20170321 develop master $ git push origin --delete 2017031001 To https://github.com/hfq-shimanqiang/payment-2.0.git - [deleted] 2017031001 ##########删除成功啦#################################
相关文章推荐
- gitHub 远程操作 常用命令 使用指南
- git常用命令,git版本控制和Xcode结合使用,用Xcode提交到github,github客户端使用
- Iwpriv工作流程及常用命令使用
- Git常用命令及GitHub入门使用
- github 常用命令及其使用说明
- GIT 版本控制软件的常用命令记录每次更新到仓库 现在我们手上已经有了一个真实项目的 Git 仓库,并从这个仓库中取出了所有文件的工作拷贝。接下来,对这些文件作些修改,在完成了一个阶段的目标和使用方法
- Git与Github使用之--常用本地命令介绍
- GitHub使用及git常用命令
- Github使用教程(二)-- Git常用命令
- Github仓库创建及git常用命令使用
- Github使用教程(二)-- Git常用命令
- Iwpriv工作流程及常用命令使用
- Github使用之常用操作命令
- 第一次使用github的客户端msysgit--msysgit的常用命令
- Iwpriv工作流程及常用命令使用之二
- Iwpriv工作流程及常用命令使用
- GitHub的使用原理与常用命令详解(一)
- [Github]msysgit的使用&Git常用命令
- github常用使用命令
- sql常用命令使用方法