ubuntu下git的安装和使用

下载和安装Git软件

$ sudo apt-get install git

配置Git软件并基于SSH生产密钥

首先在Git软件中配置自己在Github上建立的帐号的用户名和邮件地址。如果没有可以到Github上去注册先。

$ 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@youremail.com"
# Sets the default email for git to use when you commit

然后检查系统中是否已经有了一个SSH密钥:

$ cd ~/.ssh
# Checks to see if there is a directory named ".ssh" in your user directory


如果显示“No such file or directory”,则没有,需要重新建立。如果有的话,可以先备份老的密钥然后移除:

$ ls
# Lists all the subdirectories in the current directory
# config  id_rsa  id_rsa.pub  known_hosts
mkdir key_backup
# Makes a subdirectory called "key_backup" in the current directory
cp id_rsa* key_backup
# Copies the id_rsa keypair into key_backup
rm id_rsa*
# Deletes the id_rsa keypair

然后产生一个新的SSH密钥。当提示“Enter a file in which to save the key”时仅仅按Enter就可以保持默认设置,即存在自己的家目录下(“you”换成自己的Ubuntu帐号名,下同)。邮件地址与前面的和Github帐号中的相同:

$ ssh-keygen -t rsa -C "your_email@youremail.com"
# Creates a new ssh key using the provided email
# 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@youremail.com

上传密钥
在 github.com 的界面中 选择右上角的 Account Settings,然后选择 SSH Public Keys ,选择新加。
Title 可以随便命名,Key 的内容拷贝自 ~/.ssh/id_rsa.pub 中的内容,完成后,可以再使用 ssh -v git@github.com 进行测试。 SSH key列表出现你新增加的表示验证成功。
//以上在sina上有总结 下面是怎样上传自己的代码:

简单的上传下载方法

上传一个文件到Github,先需要在Github建立一个repo,然后上传。例如建立“Hello-world”文件并上传到刚建立的repo:

$ 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

上传建立的Hello-world文件,其中Hello-World为刚开始在Github上建立的repo:

$ 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"

$ git remote add origin https://github.com/username/Hello-World.git
# Creates a remote named "origin" pointing at your GitHub repo,,,username是git的username,后面的网址可以在生成repo之后直接复制
git push origin master
# Sends your commits in the "master" branch to GitHub

如果看到别人的好东西需要下载的话,先Fork别人的repo,然后Clone到你的电脑(当然也可以不Fork直接的Clone):

$ git clone https://github.com/username/Spoon-Knife.git
# Clones your fork of the repo into the current directory in terminal

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值