GIthub的少数文件上传操作 一般GitHub不能保存比较大的文件,所以我们一般用来保存我们项目中的一些脚本命令行等等 首先服务器上需要有git软件,git下面有很多子命令: usage: git ] command 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,然后点击图示的加号新建一个新的库; 这里我们填写好新库的相关说明,就可以创建一个新的库了。 点击Create repository后,GitHub会提示你后续的操作: 接下来我们按照上述步骤一步一步的将文件保存到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文件夹下的软件工具不进行上传
Windows 7/10 Github Desktop for Windows How to clone to my Github repo (It seems wrong since NOTHING is added to my repo, do not know why?!) 1. Open someone else's repo, find the button Clone or download—Open in Desktop(Start cloning to local Windows folder automatically)—Then this repo's name will appear in the Github Desktop; 2. You can right-click this repo's name (on the left navigation bar of Github Desktop),—Then the folder will be opened in Windows explorer, and you can edit it. 3. To commit the changes:Click the + symbol in the top-left of Github Desktop—Create—Change the Local path to your desired local path—Create repository—Click Publish on the top-right of Github Desktop—You can edit the name for this repo, and you can choose private—Publish XXX, and you will publish your repo At Ubuntu 1. In the command window—$mkdir Github—cd Github/—$ git clone https://github.com/XXX.git ./YYY (保存到指定名为YYY的位置)— $git add ./ (add a folder); $git add (add a file to this repo)—git commit -m — git push Do not forget to PUSH after commit! (2) How to create a new repo from Github website: https://help.github.com/articles/creating-a-new-repository/ (3) Add files through command line: see https://help.github.com/articles/adding-a-file-to-a-repository-from-the-command-line/ (4)