Github下载提速Github下载提速与Git常用命令
Github下载提速Github下载提速与Git常用命令
第一步:打开http://codeload.github.com.ipaddress.com/#ipinfo 找到你浏览器上实际显示的IP地址分别查询github.global.ssl.fastly.net和github.com, 例图 :
第二步:按win+r唤起运行框,输入cmd,然后再依次ping一下上面的两个地址
第三步:打开你C:\Windows\System32\drivers\etc\hosts文件,在文件末尾追加如下一行即可,IP地址选第二步测试TTL值小的那个。 192.30.253.121 http://codeload.github.com
另外分享一下我的github hosts,可能对你所在地区来说不是最优版本,最优hosts的选择可以参考上面三个步骤
# Github 151.101.44.249 http://github.global.ssl.fastly.net 192.30.253.113 http://github.com 103.245.222.133 http://assets-cdn.github.com 23.235.47.133 http://assets-cdn.github.com 203.208.39.104 http://assets-cdn.github.com 204.232.175.78 http://documentcloud.github.com 204.232.175.94 http://gist.github.com 107.21.116.220 http://help.github.com 207.97.227.252 http://nodeload.github.com 192.30.253.121 http://codeload.github.com 199.27.76.130 http://raw.github.com 107.22.3.110 http://status.github.com 204.232.175.78 http://training.github.com 207.97.227.243 http://www.github.com 185.31.16.184 http://github.global.ssl.fastly.net 185.31.18.133 http://avatars0.githubusercontent.com 185.31.19.133 http://avatars1.githubusercontent.com
第四步 更新DNS缓存
windows:
// 查看DNS缓存内容 ipconfig /displaydns // 删除DNS缓存内容 ipconfig /flushdns
linux:
sudo dscacheutil -flushcache
Git常用命令
环境的构建
查看版本的命令:
git --version
查看git的安装目录:
which git
常用命令
#使用git命令初始化文件夹,即创建git本地仓库 $ git init Initialized empty Git repository in /Users/Mac/Desktop/myapp/.git/ #配置全局变量 $ git config --global user.name "***" $ git config --global user.email '****@qq.com' #将index.jsp 添加到git仓库中 $ git add index.jsp #获取git本地仓库状态 $ git status #使用通配符添加文件到本地仓库,此命令表示将需要添加的本地仓库的所有html文件添加到本地仓库 $ git add *.html #此命令表示将需要添加的本地仓库的所有文件添加到本地仓库 $ git add . #从git本地仓库中移除index.jsp文件 $ git rm --cached index.jsp #将已添加到本地仓库的文件全部提交,当输入此命令时,会切换到一个编辑页面,此时需输入此次提交的备注信息,保存退出即可 $ git commit #此命令中参数'-m'后添加备注信息 $ git commit -m 'another change' #创建.gitignore文件,该文件的作用是忽略文件中的指定文件,即不用添加提交的文件 $ touch .gitignore #演示创建分支的方法,在分支下修改文件,除非合并,否则不会实质性修改主线的内容 $ git branch login #切换到master角色下 $ git checkout master #在master角色下合并分支命令 $ git merge login #以下演示同步到GitHub上 #查看是否已有远程连接 $ git remote #创建远程连接命令,"***"此内容需要在GitHub指定查看上复制 $ git remote add origin git@github.com:****/***.git #将本地仓库中的文件推送到GitHub仓库上 $ git push -u origin master #由于之前已建立连接,故此时只需直接即可push $ git push #从GitHub仓库中克隆项目到本地仓库 $ git clone **@github.com:***/homework.git
示例
Last login: Fri Mar 9 16:47:24 on ttys000 #配置git,生成公钥密钥(输完命令需要敲四次空格,后三次为提示一行敲一次),运行完之后会在~/.shh文件内生成id_rsa和id_rsa.pub两个文件, #复制id_rsa.pub内容复制黏贴到GitHub的指定位置,此操作用于git连接github网站,获取读写权限 Mac$ ssh-keygen -t rsa -b 4096 -C "1037345628@qq.com" Generating public/private rsa key pair. Enter file in which to save the key (/Users/Mac/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/Mac/.ssh/id_rsa. Your public key has been saved in /Users/Mac/.ssh/id_rsa.pub. -------------------------------------- #使用git进行项目版本管理. #1.创建myapp,并切换至该目录下 :~ Mac$ cd /Users/Mac/Desktop/myapp #创建index.jsp app.jsp文件 :myapp Mac$ touch index.jsp :myapp Mac$ touch app.jsp #使用git命令初始化文件夹,即创建git本地仓库 :myapp Mac$ git init Initialized empty Git repository in /Users/Mac/Desktop/myapp/.git/ #配置全局变量 :myapp Mac$ git config --global user.name "****" :myapp Mac$ git config --global user.email '****@qq.com' #将index.jsp 添加到git仓库中 :myapp Mac$ git add index.jsp #获取git本地仓库状态 :myapp Mac$ git status #表示正在以master(项目创建者或主线管理)角色操作 On branch master #表示没有提交过 No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) #新文件,表示需要提交的文件 new file: index.jsp Untracked files: (use "git add <file>..." to include in what will be committed) app.jsp #从git本地仓库中移除index.jsp文件 :myapp Mac$ git rm --cached index.jsp rm 'index.jsp' #获取git本地仓库状态 :myapp Mac$ git status On branch master No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) #表示需要添加git仓库的文件 app.jsp index.jsp #没有可提交的文件 nothing added to commit but untracked files present (use "git add" to track) #创建index.html文件 :myapp Mac$ touch index.html #查看git本地仓库状态 :myapp Mac$ git status On branch master No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) app.jsp index.html index.jsp nothing added to commit but untracked files present (use "git add" to track) #使用通配符添加文件到本地仓库,此命令表示将需要添加的本地仓库的所有html文件添加到本地仓库 :myapp Mac$ git add *.html :myapp Mac$ git status On branch master No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: index.html Untracked files: (use "git add <file>..." to include in what will be committed) app.jsp index.jsp #此命令表示将需要添加的本地仓库的所有文件添加到本地仓库 :myapp Mac$ git add . :myapp Mac$ git status On branch master No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: app.jsp new file: index.html new file: index.jsp #修改index.jsp 文件 :myapp Mac$ git status On branch master No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: app.jsp new file: index.html new file: index.jsp Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) #表示该文件已被修改过,需要重新添加本地仓库 modified: index.html :myapp Mac$ git add . :myapp Mac$ git status On branch master No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: app.jsp new file: index.html new file: index.jsp #将已添加到本地仓库的文件全部提交,当输入此命令时,会切换到一个编辑页面,此时需输入此次提交的备注信息,保存退出即可 :myapp Mac$ git commit [master (root-commit) f81a0ad] first commit; 3 files changed, 10 insertions(+) create mode 100644 app.jsp create mode 100644 index.html create mode 100644 index.jsp :myapp Mac$ git status On branch master #表示没有需要提交的文件 nothing to commit, working tree clean #修改app.jsp文件,获取本地仓库状态 :myapp Mac$ git status On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) #表示需要添加的文件 modified: app.jsp #表没有已经改变的已添加文件 no changes added to commit (use "git add" and/or "git commit -a") :myapp Mac$ git add . :myapp Mac$ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) #需要提交的已经添加到本地仓库的修改文件 modified: app.jsp #提交,输入备注信息 :myapp Mac$ git commit #change is app.jsp 添加备注信息 [master 24e3cd2] changed is app.jsp 1 file changed, 1 insertion(+) :myapp Mac$ git commit On branch master nothing to commit, working tree clean #创建log.txt文件 :myapp Mac$ git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) log.txt nothing added to commit but untracked files present (use "git add" to track) #创建.gitignore文件,该文件的作用是忽略文件中的指定文件,即不用添加提交的文件 :myapp Mac$ touch .gitignore #在.gitignore文件输入log.txt :myapp Mac$ git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) #需要添加文件,已忽略log.txt文件 .gitignore nothing added to commit but untracked files present (use "git add" to track) :myapp Mac$ git add . :myapp Mac$ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: .gitignore #创建文件夹dir1,dir2 :myapp Mac$ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: .gitignore Untracked files: (use "git add <file>..." to include in what will be committed) dir1/ dir2/ #在.gitignore中添加"/dir1"内容 :myapp Mac$ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: .gitignore Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: .gitignore Untracked files: (use "git add <file>..." to include in what will be committed) dir2/ :myapp Mac$ git add . #此命令中参数'-m'后添加备注信息 :myapp Mac$ git commit -m 'another change' [master 50d5a2f] another change 2 files changed, 3 insertions(+) create mode 100644 .gitignore create mode 100644 dir2/app2.js #演示创建分支的方法,在分支下修改文件,除非合并,否则不会实质性修改主线的内容 #创建login分支命令 :myapp Mac$ git branch login :myapp Mac$ git status On branch master nothing to commit, working tree clean #切换到login分支下 :myapp Mac$ git checkout login Switched to branch 'login' #在分支下创建文件 :myapp Mac$ touch login.html :myapp Mac$ git status On branch login Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: dir2/app2.js modified: index.html Untracked files: (use "git add <file>..." to include in what will be committed) login.html no changes added to commit (use "git add" and/or "git commit -a") :myapp Mac$ git commit -m 'login form' On branch login Changes not staged for commit: modified: dir2/app2.js modified: index.html Untracked files: login.html no changes added to commit :myapp Mac$ git add . :myapp Mac$ git commit -m 'login form' [login 57202e2] login form 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 login.html :myapp Mac$ git status On branch login nothing to commit, working tree clean #切换到master角色下 :myapp Mac$ git checkout master Switched to branch 'master' #在master角色下合并分支命令 :myapp Mac$ git merge login Updating 50d5a2f..57202e2 Fast-forward dir2/app2.js | 2 +- index.html | 1 + login.html | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 login.html #以下演示同步到GitHub上 #查看是否已有远程连接 :myapp Mac$ git remote #创建远程连接命令,"git@github.com:****/homework.git"此内容需要在GitHub指定查看上复制 :myapp Mac$ git remote add origin git@github.com:*****/homework.git #查看是否已有远程连接 :myapp Mac$ git remote origin :myapp Mac$ git push -u origin master git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. :myapp Mac$ git remote add origin https://github.com/*****/homework.git fatal: remote origin already exists. #将本地仓库中的文件推送到GitHub仓库上 WGB:myapp Mac$ git push -u origin master Counting objects: 18, done. Delta compression using up to 4 threads. Compressing objects: 100% (11/11), done. Writing objects: 100% (18/18), 1.46 KiB | 213.00 KiB/s, done. Total 18 (delta 3), reused 0 (delta 0) remote: Resolving deltas: 100% (3/3), done. To github.com:gdwkong/homework.git * [new branch] master -> master Branch master set up to track remote branch master from origin. #切换到master角色下 :myapp Mac$ git checkout master A README.md Already on 'master' Your branch is up-to-date with 'origin/master'. #创建文件README.md文件 :myapp Mac$ touch README.md :myapp Mac$ git add . :myapp Mac$ git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: README.md :myapp Mac$ git commit -m 'README.md' [master 2dcd73c] README.md 1 file changed, 1 insertion(+) create mode 100644 README.md #由于之前已建立连接,故此时只需直接即可push WGB:myapp Mac$ git push Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 283 bytes | 283.00 KiB/s, done. Total 3 (delta 1), reused 0 (delta 0) remote: Resolving deltas: 100% (1/1), completed with 1 local object. To github.com:gdwkong/homework.git 57202e2..2dcd73c master -> master #从GitHub仓库中克隆项目到本地仓库 :myapp Mac$ cd /Users/Mac/Desktop/myapp2 :myapp2 Mac$ ls :myapp2 Mac$ git clone git@github.com:***/homework.git Cloning into 'homework'... remote: Counting objects: 21, done. remote: Compressing objects: 100% (9/9), done. Receiving objects: 100% (21/21), done. Resolving deltas: 100% (4/4), done. remote: Total 21 (delta 4), reused 21 (delta 4), pack-reused 0 $
提交后GitHub中相应的仓库中的内容