您的位置:首页 > 编程语言

Github的基本配置与使用

2015-03-04 16:10 323 查看
第一步:尝试创建SSH key

ssh-keygen -t rsa -C xxxxx@gmail.com


默认在~/.ssh目录生成id_rsa与id_rsa.pub。

-t代表密钥类型,常见的类型有rsa1(SSH-1) 、rsa(SSH-2)、dsa(SSH-2)等;如果没有指定则默认生成用于SSH-2的rsa密钥。

-C表示提供一个新注释

第二步:在github.com的后台添加SSH key,title随意写,通过下面的命令拷贝SSH文本串:

pbcopy < ~/.ssh/id_rsa.pub


第三步:验证连接是否有效

ssh -T git@github.com


-T的解释是Disable pseudo-tty allocation. 不占用 shell 了。("it is important to do ssh test connection with -T, because some server could abort the transaction entirely if a text-terminal (tty) is requested.”)

如果是第一次连接会提示是否continue,输入yes就会看到:You’ve successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github。

第四步:在github.com建立新仓库(Repository)

按照表单填写相应内容即可。仓库建立后,页面会提示一些基本操作指令,如图所示:



下面是一些常见操作和注意点:

获取(Pull)

$cd 当前目录
$git init
$git pull git@github.com:xxx/xxx.git


提交(Push)

$cd 当前目录
$git init
$git add .  或 git add test.txt
$git commit -m "first commit"
$git remote add alias git@github.com:xxxxx/xxxxx.git
$git push alias master


当你输入“git branch”时显示本地分支(local branches)

$ git branch
debian
server
* master


当你输入“git branch -r”时显示[b]远程跟踪分支(local branches)
[/b]

$ git branch -r
cognac/master
fruitfly/server
origin/albert
origin/ant
origin/contrib
origin/cross-compile


提交多个文件

$git add file1.txt
$git add file2.txt
$git add file3.txt
$git commit  -m  "add 3 files."


修改文件后提交

$git commit -a -m "modify file1"
$git push alias master


$git commit -a里的-a是把unstaged的文件变成staged(这里不包括新建(untracked)的文件),然后commit。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: