1、git的初始设置
git config --global user.name "hechao"
git config --global user.email hechaoyuyu@gmail.com
2、建立仓库
git init
3、初始化项目
git add .
git commit -m "updates"
4、注册github账号
http://github.org
5、创建SSH密匙
ssh-keygen -C "hechaoyuyu@gmail.com" -t rsa
用ssh -v git@github.com测试
6、提交密匙
回到github的页面上,在右上方工具栏里找到Account Settings。在这个页面上有一个SSH Public Keys标签,选择Add another public key,cat ~/.ssh/id_dsa.pub 把内容粘贴到github key的空白处,然后Apply就OK了。
7、上传代码
cd到项目目录下,输入以下命令:
git remote add origin git@github.com:你的github用户名/你的github项目名.git
git push -u origin master
将整个项目上传到github的步骤:(在github上建立同名的项目获取.git)以GameBox为例 |
第一步:git init 初始化git |
第二步:git add . 添加当前目录的所有文件及子文件夹 |
第三步:git commit -m "first commit" 本地提交 -m后面的表示提交的日志 |
第四步:git remote add origin https://github.com/zhangjinglong/GameBox.git 将本地与远程仓库建立联系 |
第五步:git push -u origin master 将项目push到远程仓库 |
8、操作完毕,打完收工
从一个git库迁移到另一个git库:
1、在github中创建一个项目,以爱壁纸HD为例:
git clone git@github.com:hechaoyuyu/LoveWallpaperHD.git
2、先git pull本地的git仓库:
git pull ../LoveWallpaperHD-Linux/
3、修改变更:
git add .
git commit -m "updates"
4、push到远程仓库:
git push -u origin master
5、删除一个远程分支:
git push origin --delete branchname (git 1.7之后的版本有效)
或者
git push origin :gh-pages
如何建立自己的分支:
# 分支的创建和合并
# git branch yourbranch
# git checkout yourbranch 切换到yourbranch
# 开发yourbranch分支,然后开发之后与master分支合并
# git checkout master
# git merge yourbranch
# git branch -d yourbranch 合并完后删除本地分支
如何将牛人的远程分支更新到自己的本地分支?
# 查看当前项目下远程
# git remote
# 增加新的分支链接,例如
# git remote add niuren giturl…
# 获取牛人的远程更新
# git fetch niuren
# 将牛人的远程更新合并到本地分支
# git merge niuren/master
以上来源于http://www.yangzhiping.com/tech/github.html
# clone一个项目
# git clone giturl [dirname]
eg: git clone https://android.googlesource.com/kernel/goldfish.git goldfish_kernel
后面加一个goldfish_kernel是表示把源码clone到这个目录下
# 跟踪远程分支
# git checkout -b [分支名] [远程名]/[分支名]
# 查看所有分支
# git branch -a
# 切换分支
# git checkout -t 分支
# 修改最近的commit信息
# git commit --amend