There are a few common errors with using HTTPS with git. These errors usually indicate you have an old version of git, or you don't have access to the repository.
这几天重庆还真是热啊,不过在实验室还算不错,也是个不错的环境。之前在做内核相关的东西的时候就经常在github下载源码,觉得挺好用的,当时我也是想等有空的时候要好好学一下怎么使用的。看了两天的pdf了,感觉还是有很多收获和理解,在此与大家分享,同时也勉励自己继续学习,努力,加油。在这边博客中,过多的命令的含义我并不详细叙述,因为我的叙述比这本书《progit.zh》差远了,这本书很详细,很注重理解,所以我觉得是本好书,如果想要学习git,那就从这本书开始吧,没有比这个更好的了。
(1) 安装git,若直接用sudo apt-get install安装的话,那版本估计是比较老的版本了,所以最好下载新的版本,官网下载不到,所以我找了很久,终于在unixChina上面找到了源码,然后通过make prefix=/usr all,make prefix=/usr install安装好了.
(2) 用户信息配置:
git config --global usr.name "xiaogaogao"
git config --global usr.emailgaozw1988@126.com
git conifg --global core.editor vi
通过git config --list 可以查看配置信息
(3) 对现有项目开始用git管理:
$: git init;
$: git add .
$: git commit -m "initial project version"
其中git status 可以查看当前项目的状态,另外还有些查看差异什么的,我用的较少,毕竟我没有真正的开发什么大项目,所以掌握肯定不够全面。
(4) 查看当前的远程库:git remote -v
添加远程仓库: git remote 【shortname】 【url】,就相当于可以用shortname代替那个网址了。
抓取数据: git fetch(pull) 【remote-name】(git fetch origin)
(5) 这部分的内容就是分支的理解了,其实还是不错的,这些都是要理解的,理解了才能用好这个工具。用到时时候应该使很多的,尤其是大项目,涉及到分支和合并的东西。主要的命令为:
$:git checkout master
$:git checkout -b iss53 ;新建iss53分支,并切换到这个分支上去;
$:git merge hotfix ;合并分支hotfix和master分支;
$:git branch -d hotfix;删除分支hotfix,在讲这个内容合并到主分支之后一般会这样;
$:git branch (-v); 列出当前所有的分支
$:git branch --merged(--no-merged)查看已经合并(未合并的)的分支;
(6) 远程分支:
这部分主要理解为从网络上得到的为origin/master分支,在你开发的过程中,这个位置是保持不变的,变化的是你的master;
别人也在自己的电脑上得到origin/master分支,在他的开发过程中,这个位置也是保持不变的,变化的是他的master;
假如别人已经开发完毕,他合并到网络上的分支,这是网络上就已经变化了,你再从网络上得到的时候,就会更新你电脑上的origin/master的位置。但是你的mater的上层节点还是之前的那个,没有发生变化。
假如还有一个she也在做开发,你可以通过
$:git remote add temeone将temeone的分支假如到你的项目之中;
$:git fetch teamone 或者she的服务器上面的数据;
假如你想将自己的serverfix分支推送到网络上的awesomebranch分支去(这个分支可以没有,会自动创建)
$:git push origin serverfix:awesomebranch;
这是你的小伙伴在此从服务器上面获取数据的时候,就会获得你上传的awesomebranch分支;
$:git fetch origin; 得到输出: *【new branch】 serverfix -> origin/serverfix的字样;
但是在fetch操作抓来新的远程分支之后,你的小伙伴无法再本地编辑该远程仓库,他不会有一个新的serverfix分支,有的只是一个他无法移动的origin/serverfix指针;如果要把该内容合并到当前分支,可以运行:
$git merge origin/serverfix
若是要要一份自己的serverfix来开发,可以在远程分支的基础上分化出来一个新的分支:
$git checkout -b serverfix origin/serverfix; 这样就可以在在本地切换到serverfix继续做开发了;
衍合部分就不说了,理解多一些;如如图所示吧:
------> ------->
$ git checkout experiment
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: added staged command
----->----->--> --------->
$:git rebase --onto master server client;这基本上等于在说“检出 client 分支,找出client 分支和server 分支的共同祖先之后的变化,然后把它们在master 上重演一遍”
$ git checkout master
$git merge client
$ git checkout master
$ git merge server
$ git branch -d client
$ git branch -d server
------------------------------------------------------------------------------------------------------------上面的好乱。。。。。。。。。。。。。。。。。。。。
HTTPS cloning errors
The remote repository must exist on GitHub, and the URL is case-sensitive.
git remote -v # View existing remotes # origin https://github.com/github/reactivecocoa.git (fetch) # origin https://github.com/github/reactivecocoa.git (push) git remote set-url origin https://github.com/github/ReactiveCocoa.git # Change the 'origin' remote's URL git remote -v # Verify new remote URL # origin https://github.com/github/ReactiveCocoa.git (fetch) # origin https://github.com/github/ReactiveCocoa.git (push)
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/xiaogaogao/asdfas.git
git push -u origin master
Push an existing repository from the command line
git remote add origin https://github.com/xiaogaogao/asdfas.git
git push -u origin master