ubuntu环境
首先确定是否安装了Git管理工具
sudo apt-get install git
我选择SSH方式,比较安全方便,只需一次配置
1- 使用ssh命令连接github.com的SSH服务,登录名为[email protected](所有GitHub用户共享此SSH用户名)。
wangxiong@Dell:~/Public/GitHubRepository/PaPaPlayer$ ssh -T [email protected]
The authenticity of host 'github.com (192.30.253.113)' can't be established.
...
Permission denied (publickey).
第一次连接,会报权限被拒绝的提示,因为在本机还没有完成SSH认证,我们需要得到一个KEY密钥去完成认证.
wangxiong@Dell:~/Public/GitHubRepository/PaPaPlayer$ ssh-keygen -C "[email protected]" -f ~/.ssh/github
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/wangxiong/.ssh/github.
Your public key has been saved in /home/wangxiong/.ssh/github.pub.
The key fingerprint is:
...
一条命令生成密钥.
查看密钥用cat命令或者gedit命令文本方式打开
wangxiong@Dell:~/Public/GitHubRepository/PaPaPlayer$ gedit /home/wangxiong/.ssh/github.pub
那么Github上需要做什么呢?
在上面Title自定义,而Key是刚刚自动创建的github.pub里面的内容,是一段很长的内容,全部复制到上图的"Key"栏目里.
ubuntu下测试一下
wangxiong@Dell:~/Public/GitHubRepository/PaPaPlayer$ ssh -T [email protected]
Hi xxxxx! You've successfully authenticated, but GitHub does not provide shell access.
^ V ^ 提示授权成功了,接下来可以用SSH通道进行项目push和pull!
Step one:建立git仓库
cd到你的本地项目根目录下,执行git命令,此命令会在当前目录下创建一个.git文件夹。
wangxiong@Dell:~/Public/GitHubRepository/PaPaPlayer$ git init
Reinitialized existing Git repository in /home/wangxiong/Public/GitHubRepository/PaPaPlayer/.git/
Step two:将项目的所有文件添加到仓库中
wangxiong@Dell:~/Public/GitHubRepository/PaPaPlayer$ git add .
Step three:提交
wangxiong@Dell:~/Public/GitHubRepository/PaPaPlayer$ git commit -m "第一次提交"
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
Step four:去github上创建自己的仓库
复制SSH的链接
Step five:将本地的仓库关联到github上
wangxiong@Dell:~/Public/GitHubRepository/PaPaPlayer$ git remote add origin [email protected]:shonegg/PaPaPlayer.git
fatal: remote origin already exists.
Step six:上传代码到github远程仓库
wangxiong@Dell:~/Public/GitHubRepository/PaPaPlayer$ git push -u origin master
Counting objects: 782, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (676/676), done.
Writing objects: 100% (782/782), 6.88 MiB | 1.42 MiB/s, done.
Total 782 (delta 140), reused 0 (delta 0)
To [email protected]:shonegg/PaPaPlayer.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
OK,切换到github上现在可以看到刚刚提交的文件了!
如果用https方式提交,会要求输入用户名和密码!
每次本地文件有变动(删除或新增),都要先commit提交到本地仓库,然后push到服务端(远程仓库)分支上!
场景1:
我删除了某个文件,然后用add命令提示如下,选择git add --ignore-removal或者git add --all,前者是忽略删除,后者是处理删除这一动作.
wangxiong@Dell:~/Public/GitHubRepository/PaPaPlayer$ git add .
warning: You ran 'git add' with neither '-A (--all)' or '--ignore-removal',
whose behaviour will change in Git 2.0 with respect to paths you removed.
Paths like 'app/src/main/res/values/bilibili_strings.xml' that are
removed from your working tree are ignored with this version of Git.
* 'git add --ignore-removal ', which is the current default,
ignores paths you removed from your working tree.
* 'git add --all ' will let you also record the removals.
Run 'git status' to check the paths you removed from your working tree.
wangxiong@Dell:~/Public/GitHubRepository/PaPaPlayer$ git add --all
我要达到把本地仓库的对应文件删除掉这一效果,那么就用第二种方式
wangxiong@Dell:~/Public/GitHubRepository/PaPaPlayer$ git add --all
wangxiong@Dell:~/Public/GitHubRepository/PaPaPlayer$ git commit -m "添加README.md"
[master f6d54c5] 添加README.md
4 files changed, 6 insertions(+), 43 deletions(-)
create mode 100644 README.md
create mode 100644 README.md~
rewrite ScreenShots/Screenshot_2016-07-23-12-21-31.png (95%)
delete mode 100644 app/src/main/res/values/bilibili_strings.xml
从终端提示,可以看出,提交到本地库后,有4个文件改变了,创建了2个文件README.md和README.md~(临时文件),重写了一个图片文件,删除了一个xml文件
说到这,Github上上传README.md的说明文件时,通常都会展现截图效果图,那这是如何做到的呢?
Github上的README.md文件是使用的Markdown语言编写的
Markdown插入图片的语法是 ![] (图片url)
1:在本地建立ScreenShots效果图的文件夹,将效果图放入
2:提交到github上
3:取图片地址,注意我点击的Download选项,如果有raw选项,点击raw!
拷贝这个链接到md文件,就可以显示图片啦!
我用的Markdown编辑工具,是StackEdit,一个开源免费工具
https://stackedit.io
效果:
Export导出.md: