社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
首先参考:http://callmepeanut.blog.51cto.com/7756998/1304912
一、注册一个GitHub账号
二、新建一个仓库
每次向GitHub提交的代码都会被放到一个仓库(repo)。为了把你的项目放到GitHub上,你需要有一个GitHub仓库来“入住”。
点击新仓库
在新的页面里填上仓库的名称(因为已经创建过了,所以为提示冲突):
点击创建后就OK了!
三、安装和配置git
使用yum安装
1
|
yum
-y install git |
完成后查看是否成功
1
2
|
[root@localhost
~]# git --version git
version 1.7 . 1 |
可以看到安装成功了,如果使用源码可以安装最新版本的。
接着就要设置用户名和Email了,Email最好和注册时候的一样。
1
2
3
4
|
$
git config --global user.name "Your
Name Here" #
Sets the default name for git to use when you commit $
git config --global user.email "your_email@example.com" #
Sets the default email for git to use when you commit |
上面的内容都写在配置文件~/.gitconfig里了
恭喜,到这里,基本Git和GitHub都配置好了!
四、创建和提交项目
这里给官方提供的例子吧,Hello-World为项目名称。
1
2
3
4
5
6
7
8
9
|
$ mkdir ~ /Hello-World #
Creates a directory for your project called "Hello-World" in your user directory $ cd ~ /Hello-World #
Changes the current working directory to your newly created directory $
git init #
Sets up the necessary Git files #
Initialized empty Git repository in /Users/you/Hello-World/.git/ $ touch README #
Creates a file called "README" in your Hello-World directory |
如果已经有项目了,就只用切换到项目目录,然后git init。
接着向Git提交修改
1
2
3
4
|
$
git add * #
Stages your README file, adding it to the list of files to be committed $
git commit -m 'first
commit' #
Commits your files, adding the message "first commit" |
这里所有的更改都只是在本地的。Push之后才会提交到GitHub保存:
1
2
3
4
|
$
git remote add origin https: //github .com /username/Hello-World .git #
Creates a remote named "origin" pointing at your GitHub repository $
git push origin master #
Sends your commits in the "master" branch to GitHub |
成功之后就可以在网页上看到添加的文件了:
可是我的最后一步git push origin master出现问题:
fatal: unable to access 'https://github.com/git/git.git/': SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Setp1:从curl官网下载cacert.pem文件(下载链接参见这里,关于curl的Server SSL Certificates细节参见这里,其中提到,从curl 7.18.0开始,编译安装curl时默认安装ca证书,而我机器的curl version=7.12.1,curl --version可查看):
执行git
push origin master再次出现问题:
error: failed to push some refs to 'git@github.com:dearjohn/tutorial.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
解决方法:github上面已有的README.RM,但是本地没有。引起冲突。
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!