初学git,初始化库|添加文件ignore|提交方法

1.初始化git仓库:

  进入任意目录,右键选择:Git Bash Here,输入命令:git status 查看当前git库的状态。

  如要排除文件,在库根目录下创建.gitignore文件(新建文件改名为:.gitignore.)即可创建。

 

  在其中可用:*.type  !*out.type  folder/  a?b.type  *.cp[cod]  表示将会忽略的文件

  *通配符  type表示文件类型  !从将要排除的文件中排除这样的文件(即不忽略)  

  folder/表示当前相对路径下文件夹folder的所有文件  ?单配符  [cod]忽略一位单字符

  已有预定义的文件供使用:github/gitignore

  如果有想要忽略的文件已被track,则输入如下命令可解决:

git rm -r --cached .
git add .
git commit -m 'update .gitignore

2.添加文件:

  git add .  //添加当前库中所有文件、文件夹

  git commit -m "note"  //提交,"note" 记录你对此次提交想说的话

3.连接github并push

  登入github.com

创建一个空仓库,进入后有提示如下:

…or create a new repository on the command line

echo "# Text" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/username/Text.git git push -u origin master 

…or push an existing repository from the command line

git remote add origin https://github.com/username/Text.git
git push -u origin master

…or import code from another repository

You can initialize this repository with code from a Subversion, Mercurial, or TFS project.

用第一种方法,在bash中每行单独输入,其中(username)为用户名称:
$ git remote add origin https://github.com/username/Text.git
git push -u origin master

 

  此时,库中的文件已经全部推送成功!

猜你喜欢

转载自www.cnblogs.com/jiangyz/p/9689579.html