现在的位置: 首页 > 综合 > 正文

github应用小记(LINUX)

2018年02月20日 ⁄ 综合 ⁄ 共 1457字 ⁄ 字号 评论关闭

    github是一个分布式的项目托管站点,方便项目的管理,最近一些代码放在自己的机器上感觉不安全,架设一个svn又太繁琐,所以选择使用github。

在linux上使用github有以下步骤:

1、申请账号,创建project.git项目
2、在linux上安装git

yum install git

3、生成github使用的秘钥对

ssh-keygen -t rsa -C "your_email@youremail.com"

4、在github站点上添加ssh秘钥

登陆github系统。点击右上角的 Account Settings--->SSH Public keys ---> add another public keys

把你本地生成的密钥复制到里面(key文本框中), 点击 add key 就ok了

5、测试是否成功

ssh -T git@github.com

如果提示:Hi xxx You've successfully authenticated, but GitHub does not provide shell access. 说明你连接成功了

6、创建本地工作目录

mkdir
project

# cd project
# git init
# touch README
# git add README
# git commit -m 'first commit'
定义远程服务器别名origin
#  git remote add origin git@github.com:xxx/project.git   
本地和远程合并,本地默认分支为master
# git push origin master

7、 更新文件

# vi README
自动commit更改文件
# git commit -a     
更新至远程
# git push origin master

8、 创建和合并分支

#git branch 显示当前分支是master
#git branch new-feature  创建分支
# git checkout new-feature 切换到新分支
# vi page_cache.inc.php
# git add page_cache.inc.php
Commit 到本地GIT
# git commit -a -m "added initial version of page cache"
合并到远程服务器
# git push origin new-feature

如果new-feature分支成熟了,觉得有必要合并进master
#git checkout master
#git merge new-feature
#git branch
#git push 
则master中也合并了new-feature 的代码

9、删除文件

git
rm --cached filename 

git commit -m "hehe" 
git push origin branch 
--cached 的指令 都是和staging area或者叫index有关的,就是git add了但还没有commit出去的状态。 
git rm --cached filename 把文件从staging area中删了,再commit,push,就把github里面那份也删了。

常见错误

ssh-add
可能会出现以下错误

Could not open a connection to your authentication agent.

这是因为ssh-agent没有运行,执行

exec
ssh-agent bash

问题就迎刃而解了,相关问题可查阅http://linux.101hacks.com/unix/ssh-add/

其他参见 http://luozhaoyu.iteye.com/blog/1461705

抱歉!评论已关闭.