Git分布式文件管理工具与使用GitHub托管项目

发布于 2012-06-05 | 更新于 2020-09-20

最近使用到了github托管项目,所以了解下Git。

Git是一个分布式的版本控制系统,GitHub可以托管各种git库,并提供一个web界面,但与其它像 SourceForge或Google Code这样的服务不同,GitHub的独特卖点在于从另外一个项目进行分支的简易性。为一个项目贡献代码非常简单︰首先点击项目站点的“fork”的按 钮,然后将代码检出并将修改加入到刚才分出的代码库中,最后通过内建的“pull request”机制向项目负责人申请代码合并。已经有人将GitHub称为代码玩家的MySpace。

1、下载Git客户端:

http://code.google.com/p/msysgit/downloads/list

  • 2、使用Git客户端设置Git:

可以参考:https://help.github.com/articles/set-up-git

设置用户名:

1
2
$ git config --global user.name "Your Name Here"
\# Sets the default name for git to use when you commit

设置Email,可以不用真实的Email,只是作为一个标示:

1
2
$ git config --global user.email "your_email@youremail.com"
\# Sets the default email for git to use when you commit

设置密码缓存时间:

1
2
3
4
$ git config --global credential.helper cache
\# Set git to use the credential memory cache
$ git config --global credential.helper 'cache --timeout=3600''
\# Set the cache to timeout after 1 hour (setting is in seconds)

3、在服务器上创建一个仓库:

可以参考:https://help.github.com/articles/create-a-repo

4、初始化本地仓库:

1
2
3
4
5
6
7
$ 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/

5、添加文件:

1
2
$ touch README
\# Creates a file called "README" in your Hello-World directory

6、提交文件到本地仓库:

1
2
3
4
$ git add README
\# 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"

7、生成SSH Key:

使用GitHub首先要创建SSH Key。SSH将用来加密本机与远端服务器之间的通信。同时也是识别你对代码所做的变更的方法。SSH Key可以使用Git命令行来产生。首先打开Git Bash命令行,输入:

1
ssh-keygen -C "username@email.com" -t rsa

说明:username@email.com 为你初始化Git的设置的Email地址。

之后Git Bash命令行中,会进行一些提示:

保存位置:注意rsa key pair要生成到root directory: ~/.ssh/目录下,如生成到C:\Users\arthinking\.ssh\id_rsa.pub。 pass phrase:如果本机安全,也可以不用输入。

找到生成的id_rsa.pub文件,把里面的内容复制到GitHub -> Account Settings -> SSH Keys –>Add SSH key的key输入框中,标题自定义,进行添加一个SSH Key。

8、把本地仓库提交到服务器:

1
2
3
4
$ git remote add origin git@github.com:username/Hello-World.git
\# Creates a remote named "origin" pointing at your GitHub repo
$ git push origin master
\# Sends your commits in the "master" branch to GitHub

注意,这里的Hello-World.git是根据你在服务器上创建的仓库名称决定的,如果服务器创建了一个Itzhai仓库,则这里为Itzhai.git。

本文作者: arthinking

本文链接: https://www.itzhai.comgit-distributed-file-management-tools-and-use-github-managed-project.html

版权声明: 版权归作者所有,未经许可不得转载,侵权必究!联系作者请加公众号。

×
IT宅

关注公众号及时获取网站内容更新。

请帅旋喝一杯咖啡

咖啡=电量,给帅旋充杯咖啡,他会满电写代码!

IT宅

关注公众号及时获取网站内容更新。