> Ubuntu >

Ubuntu环境下使用Git管理Github代码

在ubuntu(Linux)环境中对代码的管理,git显然是不可缺少的一部分,而Github自然是最好的选择。

一,安装

首先要使用Git,必须安装Git,在ubuntu中安装Git比较简单:

$ sudo apt-get install git git-core

二,配置

在 https://github.com/settings/ssh 页面有Add SSH KEY,需要生成key并将其添加到这里,生成key的代码如下:

$ ssh-keygen -t rsa -C "your_email@example.com"

# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
# Enter file in which to save the key (/home/you/.ssh/id_rsa):

Enter passphrase (empty for no passphrase): [Type a passphrase]
# Enter same passphrase again: [Type passphrase again]

Your identification has been saved in /home/you/.ssh/id_rsa.
# Your public key has been saved in /home/you/.ssh/id_rsa.pub.
# The key fingerprint is:
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com

然后你需要Ctrl+H,在~目录的.ssh中找到id_rsa,拷贝内容并添加奥github之前的那个位置中,然后测试:

ssh -T git@github.com
# Attempts to ssh to github

The authenticity of host 'github.com (207.97.227.239)' can't be established.
# RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
# Are you sure you want to continue connecting (yes/no)?

Hi username! You've successfully authenticated, but GitHub does not
# provide shell access.

三,使用

向Github中上传代码,需要先在github中新建一个repo,记录名字,
不要选择创建readme文件,然后会出来一个介绍如何使用的页面,按照提示操作即可:

创建新的Repo:

#官方提示

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:thonatos/tetst.git
git push -u origin master

#个人使用

cd workpath
git init 
git add . (.后面有空格)
git commit -m "Init"
git remote add origin git@github.com:thonatos/tetst.git
git push -u origin master

向已经存在的Repo中添加代码:

git remote add origin git@github.com:thonatos/tetst.git
git push -u origin master

大概就这么多了,基本按照提示操作即可。

(责任编辑:IT)