Linux-Git-1

来源:互联网 发布:棕榈大道 知乎 编辑:程序博客网 时间:2024/06/18 11:07

概要:介绍Git工具的基本使用方式。

主要参考的网址:

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

1.初始化一个仓库。

使用的命令是:git init

如果一不小心错将其他目录初始化,只需要执行

rm -rf .git 

删除目录下的.git目录,就可以了。

2.克隆项目到本地

git clone https://github.com/GitHubSi/fuhui.git

但是该方式并不能正常克隆文件,修改成

 git clone git://github.com/GitHubSi/fuhui.git

程序暂时可以正常运行克隆。

3.本地仓库由git维护的3个工作流

工作区域-暂存区-HEAD

4.编辑README.md文件,使用git add 将文件添加到暂缓区

git add README.md

如果这个时候发现add了多个不必要的文件,想要撤销怎么办,使用

git reset HEAD <file>

5.将改动提交到HEAD区

git commit -m '测试使用git推送到HEAD'

出现了错误

unable to auto-detect email address (got 'fuhui@ubuntu.(none)')

6.修改配置文件如下

git config --global user.email "2493393471@qq.com"git config --global user.name "GitHubSi"

7.将HEAD区中的代码推送到远程服务器端

git push origin master

其中master可以换成你想要推送的任何分支

出现了错误

You can't push to git://github.com/GitHubSi/fuhui.git

那么就会出现这个问题,因为这个protocol是不支持push的。

8.修改克隆指令

git clone git@github.com:username/fuhui.git

出现了错误

Permission denied (publickey).fatal: Could not read from remote repository.

9.添加密钥

ssh-add ~/.ssh/fuhui_rsa

出现提示

Could not open a connection to your authentication agent.

10.修改步骤9,在步骤9之前执行

ssh-agent bashssh-add ~/.ssh/fuhui_rsa

出现提示

/root/.ssh/fuhui_rsa: No such file or directory

11.密钥添加不成功,所以参照官网,添加认证
参考网址:

https://help.github.com/articles/generating-ssh-keys/

步骤如下:

ssh-keygen -t rsa -b 4096 -C "2493393471@qq.com"eval $(ssh-agent -s)ssh ~/.ssh/id_rsa

然后拷贝id_rsa.pub文件中的内容,在github中生成SSH Key。测试连接是否能够建立

ssh -T git@github.com

12.创建分支

git checkout -b fuuhi-branch

13.更新项目

git pull
0 0
原创粉丝点击