Newly1992的个人博客分享 http://blog.sciencenet.cn/u/Newly1992

博文

GitHub基础教程

已有 2269 次阅读 2019-10-14 15:15 |系统分类:科研笔记| 生物信息, GitHub

GIthub的少数文件上传操作

一般GitHub不能保存比较大的文件,所以我们一般用来保存我们项目中的一些脚本命令行等等

首先服务器上需要有git软件,git下面有很多子命令:

usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
          [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
          [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
          [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
          <command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
  clone      Clone a repository into a new directory
  init       Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
  add        Add file contents to the index
  mv         Move or rename a file, a directory, or a symlink
  reset      Reset current HEAD to the specified state
  rm         Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
  bisect     Use binary search to find the commit that introduced a bug
  grep       Print lines matching a pattern
  log        Show commit logs
  show       Show various types of objects
  status     Show the working tree status

grow, mark and tweak your common history
  branch     List, create, or delete branches
  checkout   Switch branches or restore working tree files
  commit     Record changes to the repository
  diff       Show changes between commits, commit and working tree, etc
  merge      Join two or more development histories together
  rebase     Reapply commits on top of another base tip
  tag        Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
  fetch      Download objects and refs from another repository
  pull       Fetch from and integrate with another repository or a local branch
  push       Update remote refs along with associated objects

首先我们需要登陆GitHub,然后点击图示的加号新建一个新的库;

1570761880074.png

这里我们填写好新库的相关说明,就可以创建一个新的库了。

1570762460061.png

点击Create repository后,GitHub会提示你后续的操作:

1570762994073.png

接下来我们按照上述步骤一步一步的将文件保存到Github中:

echo "# Git-Test" >> README.md   # 建立一个新的文件
git init                                               # 这一步会新建一个.git文件夹,
## Initialized empty Git repository in /mnt/git_test/.git/
ls -a
##.  ..  .git  README.md
git add README.md                       # 将README.md文件add到服务器的git目录下,等待下一步的上传保存
git commit -m "first commit"         # commit记录这一次的更新内容,注意这里如果是第一次操作会提示你需要设置你的User.email和User.name,这里就按照提示的命令进行设置就行。设置完以后需要重新git commit
git config --list                               # 上面设置完后可以用这条命令查看你的User.name和User.email以及其他的一些设定
git remote add origin https://github.com/<yourusername>/Git-Test.git #这里相当于将你的文件夹和新建的库网址进行绑定
git push -u origin master             # 将服务器add的内容push到GitHub上的库中,这里需要输入你的GitHub用户名以及密码。

经过上述操作就将README.md push到了Github上,接下来只要三步就可以将文件上传。

#这里我们对一个文件夹中的文件进行上传的操作
git add scripts/*                         # 首先将文件夹中的文件都add到git库中
git commit -m "Add scripts"     # 设置更新的内容信息
git push origin master              # 将文件push到Github中,这里同样需要输入用户名和密码

项目文件的上传操作

一般来说我们一个项目中会有很多不同格式的文件,并且有很多文件时非常大的,我们无法上传到Github中(单个文件大小不能超过100Mb),但是一个一个上传的话,每次更新就会很麻烦,所以我们可以设置不上传的文件格式筛选目录,然后根据我们设置的筛选目录进行上传,可以很方便快捷的将整个项目文件进行更新。这里我们会用到gitignore文件。

git add .                       # 这里的'.'时通配符的意思,就是将当前目录下所有的文件包括文件夹都add到git 库中
vi .gitignore                # 创建gitignore文件,将筛选的文件后缀名写到文件中

gitignore文件其实就是将你不想上传的文件名写到里面,然后在上传的时候就会忽略写在gitignore中的文件,gitignore的一般书写方式如下:

# Ignore everything          这里的'*'表示忽略所有的东西。
*                              


# But not these files...       但是不忽略以下这些文件 '!'表示取反,这里写入要上传的文件后缀
!.gitignore
!*.pl
!*.py
!*.R
!*.README
!*.sh
!*.ipynb
!*.md


# ...even if they are in subdirectories  即使这些文件在文件夹中也不忽略
!*/


tool/                              # 这里将tool文件夹下的软件工具不进行上传





https://blog.sciencenet.cn/blog-3416913-1201866.html


下一篇:批量下载某一物种的基因序列
收藏 IP: 117.178.112.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-20 03:31

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部