git使用简易指南

http://www.bootcss.com/p/git-guide/

简单操作

更新远程仓库

1
2
3
4
5
6
# 不会同步删除操作
git add *
# 会同步所有,包括删除文件的操作
# git add -A
git commit -m "some description"
git push

更新本地仓库

但是更新后然后用上面方式更新会是merge到master而不是更新master

1
git pull 或者 git fetch origin master

创建分支

1
2
3
4
git checkout -b iss53
# 上面的命令相当于
git branch iss53
git checkout iss53

删除分支

1
git branch -d hotfix

新建repository

目前用的最笨的手动创建repository,然后git clone到本地,然后往本地的文件夹添加文件,再push上去

问题集合

git push提示没有权限

设置Git的user name和email

1
2
git config --global user.name "yourname"
git config --global user.email "youremail"

生成SSH密钥

1
2
3
4
5
6
7
8
9
10
查看是否已经有了ssh密钥:cd ~/.ssh
如果没有密钥则不会有此文件夹,有则备份删除
生存密钥:
ssh-keygen -t rsa -C “haiyan.xu.vip@gmail.com”
按3个回车,密码为空。
Your identification has been saved in /home/tekkub/.ssh/id_rsa.
Your public key has been saved in /home/tekkub/.ssh/id_rsa.pub.
The key fingerprint is:
………………
最后得到了两个文件:id_rsa和id_rsa.pub

添加密钥到ssh:ssh-add 文件名,需要之前输入密码.

在github上添加ssh密钥,这要添加的是“id_rsa.pub”里面的公钥。
打开https://github.com/,在设置中添加密钥

1
2
3
4
5
6
7
测试:ssh git@github.com
The authenticity of host ‘github.com (207.97.227.239)’ can’t be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘github.com,207.97.227.239′ (RSA) to the list of known hosts.
ERROR: Hi tekkub! You’ve successfully authenticated, but GitHub does not provide shell access
Connection to github.com closed.

如何修改github上仓库的项目语言?

问题原因:

github 是根据项目里文件数目最多的文件类型,识别项目类型.

解决办法:

项目根目录添加 .gitattributes 文件, 内容如下 :

1
2
3
*.swift linguist-language=objective-c

作用: 把项目里的 .swift 文件, 识别成 objective-c 语言