您的位置:首页 > 编程语言

在Ubuntu上创建Git仓库并上传到GitHub

2017-04-11 02:48 183 查看


1、安装 Git

$ sudo apt-get install git git-core


  检查:
git --version


2、基本配置

$ git config --global user.name <your-name>
$ git config --global user.email <your-email>


3、假设项目名为 helloworld,执行下面命令,进到项目目录,创建版本库

$ cd helloworld
$ echo "# helloworld" >> README.md
$ git init


4、Staging 被修改的文件,并提交更新

$ git add .
$ git commit -m "first commit"


5、仓库托管到 GitHub,需要 SSH Key 验证,执行下面命令创建 SSH Key

$ ssh-keygen -t rsa


  之后在 ~/.ssh/ 目录下可以看到
id_rsa
id_rsa.pub
两个文件。这两个就是 SSH Key 的秘钥对,其中,
id_rsa
是私钥,不能泄露出去,
id_rsa.pub
是公钥,可以放心地告诉任何人。

6、然后登陆 GitHub,上传 SSH Key 公钥

  依次选择“Settings –> SSH and GPG keys –> New SSH key”,填上适当的 Title,并复制
id_rsa.pub
文件的内容粘贴在 Key 文本框里。

7、在 GitHub 上新建一个仓库(假设名为 helloworld),然后执行如下命令

$ git remote add origin https://github.com/<your-name>/helloworld.git[/code] 
8、接着,就可以把本地仓库的所有内容推送到远程仓库

$ git push -u origin master


可能遇到的问题:

1、remote: fatal: early EOF

  在repo sync 时,,出现“remote: fatal: early EOF”错误,解决方法是修改家目录下 .gitconfig 文件,添加如下内容:

[core]
compression = -1


2、提示如下警告

remote: warning: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.

remote: warning: See http://git.io/iEPt8g for more information.

remote: warning: File xxx is 55.80 MB; this is larger than GitHub’s recommended maximum file size of 50.00 MB

  这是因为有的文件大小超过 50 MB,参考说明,可知:GitHub will warn you when pushing files larger than 50 MB. You will not be allowed to push files larger than 100 MB.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: