目的
通过Git管理github托管项目代码
下载安装
1.Git官网下载https://git-scm.com/downloads
2.双击安装
git是在终端中使用!!!!
2.设置用户名邮箱
git config --global user.name ‘Zhangzeguo’
git config --global user.email ‘1271507390@qq.com’
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹
$
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹
$ git config --global user.name '1271507390'
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹
$ git config --global email.name '1271507390@qq.com'
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹
$ mkdir test
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹
$ pwd
/e/新建文件夹
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹
$ cd test #进入到test文件夹里面
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹/test
$ git init #初始化操作,这样会建立一个隐藏文件
Initialized empty Git repository in E:/新建文件夹/test/.git/
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹/test (master)
$ touch a1.php #向仓库添加文件
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹/test (master)
$ git status #查看状态
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
a1.php
nothing added to commit but untracked files present (use "git add" to track)
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹/test (master)
$ git add a1.php #将文件添加到暂存区
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹/test (master)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: a1.php
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹/test (master)
$
将文件从暂存区提交到仓库
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹/test (master)
$ git commit -m 'add a1.php' #将文件从暂存区提交到仓库
[master (root-commit) 0daca67] add a1.php
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a1.php
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹/test (master)
$ git status
On branch master
nothing to commit, working tree clean
Git管理远程仓库
使用远程仓库的目的
作用:备份,实现代码共享集中化管理
Git 克隆操作
目的
将远程仓库(github对应的项目)复制到本地
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹
$ git clone https://github.com/Zhangzeguo/Hello-Word.git
Cloning into 'Hello-Word'...
remote: Enumerating objects: 19, done.
remote: Counting objects: 100% (19/19), done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 19 (delta 4), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (19/19), 4.92 KiB | 21.00 KiB/s, done.
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹
$ vi a2.py #这是错误操作
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹
$ touch Hello-Word #这是错误操作
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹
$ cd Hello-Word
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹/Hello-Word (master)
$ vi a1.php
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹/Hello-Word (master)
$ git add a1.php
warning: LF will be replaced by CRLF in a1.php.
The file will have its original line endings in your working directory
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹/Hello-Word (master)
$ git commit -m '第二次通过git提交到仓库'
[master 5647ad4] 第二次通过git提交到仓库
1 file changed, 3 insertions(+)
create mode 100644 a1.php
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹/Hello-Word (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹/Hello-Word (master)
$ git push
fatal: unable to access 'https://github.com/Zhangzeguo/Hello-Word.git/': Failed to connect to github.com port 443: Timed out
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹/Hello-Word (master)
$ git push
fatal: unable to access 'https://github.com/Zhangzeguo:Ab151001217/Hello-Word.git/': The requested URL returned error: 400
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹/Hello-Word (master)
$ git push
fatal: unable to access 'https://Zhangzeguo:Ab151001217/Hello-Word.git/': URL using bad/illegal format or missing URL
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹/Hello-Word (master)
$ git push
remote: Not Found
fatal: repository 'https://github.com/Hello-Word.git/' not found
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹/Hello-Word (master)
$ git push
remote: Repository not found.
fatal: repository 'https://github.com/Zhagnzeguo/Hello-Word.git/' not found
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹/Hello-Word (master)
$ git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 403 bytes | 50.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/Zhangzeguo/Hello-Word.git
7f68c58..5647ad4 master -> master
Administrator@PC-20190805HKSX MINGW64 /e/新建文件夹/Hello-Word (master)
注:之所以push了这么多变是因为之前的用户名和密码格式不对。