创建Git仓库

创建Git仓库

十月 21, 2019

创建Git仓库

两种场景:

1.把已有的项目代码纳入Git管理

$ cd 项目代码所在的文件夹
$ git init

2.新建的项目直接用Git管理

$ cd 某个文件夹
$ git init your_project #会在当前路径下创建和项目名称同名的文件夹
$ cd your_project

创建一个仓库,设置local配置

$ git init LocalTest
Initialized empty Git repository in /Users/jamme/Documents/WorkSpace/GitTest/LocalTest/.git/
$ ls
LocalTest
$ cd LocalTest/
$ git config --local user.name 'xxx'
$ git config --local user.email 'xxx@xxx.com'
$ git config --local --list
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
user.name=xxx
user.email=xxx@xxx.com

提交一个文件,并查看状态及日志

$ cp ../readme . #拷贝事先创建好的readme文件到当前目录
$ git add readme #先add readme文件
$ git status #查看当前路径的状态
On branch master

No commits yet

Changes to be committed:
(use "git rm --cached <file>..." to unstage)

new file: readme

$ git commit -m'Add readme' #提交readme文件,并在-m后添加提交信息
[master (root-commit) 33f7ae4] Add readme
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 readme
$ git log #查看git日志
commit 33f7ae4c4d4da85453ed0077670e242b71d0a621 (HEAD -> master)
Author: xxx <xxx@xxx.com>
Date: Sun Apr 28 22:19:09 2019 +0800

Add readme