2 Github Local Pull Github


1 安装与配置

1.win下载git工具:git bash 、git gui 、git cmd https://git-scm.com/downloads linux环境下如果yum源有git包,

yum -y install git-all.noarch

若没有还是去官网下载。

2.打开git bash,执行以下命令,配置git的用户名邮箱

$ git config --global user.name "hanyuntao"
$ git config --global user.email "hanyuntaocn@163.com"
$ git config --list

3。 设置SSH key(git中sshkey有何作用?)

首先检查是否已生成密钥cd ~/.ssh,如果返回的ls有3个文件,则密钥已经生成。

$ ssh-keygen -t rsa -C "hanyuntaocn@163.com"
ssh -T git@github.com   #远程登录git

2. 界面创建github

3 创建仓库上传github或gitlab

非常简单,起名字,描述库的作用功能,设置公有,私有。 是否设置创建README,如果之前没有设置它,上传文件就会报错。 否则执行以下命令:

git init
echo "# github-roam" >> README.md
git add README.md
git commit -m 'first_commit'
git remote add origin https://github.com/findingsea/myRepoForBlog.git
git push origin master

4. 上传本地项目到github或gitlab

cd d:test   #某一个文件目录
git init     #初始化为库
git add .   #添加上传内容 ,如果报错,尝试git add --all
git commit -m "test four"    #编写描述内容
git remote  #查看远程主机名(一个远程库伪主机的主机名)
git remote add origin https://github.com/Ghostwritten/tutorial.git   添加远程库名
git push origin master  #推送到库

5. 解决错误

错误1

1.To https://github.com/Ghostwritten/test.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/Ghostwritten/test.git'
git push origin master --force   #强制推送到库名下

错误2

git remote add origin https://github.com/findingsea/myRepoForBlog.git,出现错误:
  fatal: remote origin already exists

则执行以下语句:

git remote rm origin
git remote add origin https://github.com/findingsea/myRepoForBlog.git 

错误3

在执行git push origin master时,报错:
error:failed to push som refs to.......
则执行以下语句:
git pull origin master
先把远程服务器github上面的文件拉先来,再push 上去。

可以看到我们的本地项目已经上传到了github上了。

Last updated