git和github使用整理

来源:互联网 发布:amd 知乎 编辑:程序博客网 时间:2024/06/05 11:36

可能出现的错误提示

1、在执行$ git remote addorigin git@github.com:defnngj/hello-world.git

提示错误:fatal: remote origin already exists.

解决办法

$ git remote rm origin

然后在执行:$ git remote add origin git@github.com:defnngj/hello-world.git 就不会报错误了

2、 在执行$ git push origin master

提示错误:error:failed to push som refs to…….

解决办法:

$ git pull origin master // 先把远程服务器github上面的文件拉下来,再push 上去。

3、在.bash_profile配置了adb环境变量后,输入adb命令有效,但是重启iterm窗口就提示command not found

解决办法:

打开.zshrc文件,在最后面添加

# Enable my profilesource ~/.bash_profile

即可

初始创建github项目

获取key

1、进入.ssh目录,查看目录中文件
如果里面有文件,建议清理原ssh密匙
例如:

$ ls config id_rsa id_rsa.pub known_hosts$ mkdir key_backup$ cp id_rsa* key_backup$ rm id_rsa*

2、获取密匙:

ssh-keygen -t rsa -C "liuhuajian_lhj@163.com"//填写email地址,然后一直“回车”ok

生成的id_rsa.pub文件中的内容,就是ssh密匙

3、将生成密匙添加到github中:
登陆github,点击右上角的 Settings—>ssh and GPG keys —> add new public keys即可

测试

测试是否连接成功

$ ssh -T git@github.com

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

配置用户信息

$ git config --global user.name "liuhuajian"//给自己起个用户名$ git config --global user.email  "liuhuajian_lhj@163.com" //邮箱

新建一个项目

1、 回到github首页,点击页面右下角“New Repository”

填写项目信息:

project name: hello world

description : my first project

点击“Create Repository”

现在完成了一个项目在github上的创建。

2、我们需要使用git在本地创建一个相同的项目。

$ makdir ~/hello-world    //创建一个项目hello-world$ cd ~/hello-world    //打开这个项目$ git init    //初始化 $ touch README$ git add README   //更新README文件$ git commit -m 'first commit'//提交更新,并注释信息“first commit” $ git remote add origin git@github.com:defnngj/hello-world.git   //连接远程github项目  $ git push -u origin master   //将本地项目更新到github项目上去
原创粉丝点击