GitHub 上传及下载代码
github是开源的代码管理工具,同时也是一个很好的开源学习平台,学习如何使用github也是非常重要的,以下是我梳理的一些常用的命令
配置
首先初次运行配置全局的用户名和密码,不然以后每次添加都需输入用户名和密码这样比较繁琐,在打开的git shell中输入这个,替换里面的[username]和[email]
git config –global user.name [username]
git config –global user.email [email]
可以通过git config –list命令查看当前gitshell的一些设置
$ git config --list
core.symlinks=false
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
..........
初始化
配置完成之后,进入你的目录,先运行一个初始化命令
git init
添加
接下来就是你要添加的文件,用git add命令
git add . (表示添加所有改变)
- git add . :他会监控工作区的状态树,使用它会把工作时的所有变化提交到暂存区,包括文件内容修改(modified)以及新文件(new),但不包括被删除的文件。
- git add -u :他仅监控已经被add的文件(即tracked file),他会将被修改的文件提交到暂存区,add -u 不会提交新文件(untracked file)。(git add –update的缩写)
- git add -A :是上面两个功能的合集(git add –all的缩写)
- git add后面接文件或者文件夹则会将这个文件或者文件夹提交
提交注释
git commit -m 提交注释文件,说明本次修改的内容和其他说明
git commit -m “需要说明的内容”
再提交之前需要用git status 命令擦好看里面提交内容的变化,确认后再提交
关联respositories
接下来也是比较重要的一步关联github的项目可以进入需要添加的项目复制里面的URL
在gitshell中运行以下命令,这样其实origin就代表这个地址 https://github.com/*/MapReduce 当然你也可以用其他的名字如origin2等等,或者添加多个respositories,在push的时候添加对应的变量名称就行了;
git remote add origin https://github.com/*/MapReduce
向respositories push更新
最后一步就是push命令了
输入以下命令提交修改,其中后面的master表示版本号,origin是前面取得remote地址的名字提交之后后显示,表示push成功。
git pull origin master
$ git push -u origin
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 402 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/HubSKY/MapReduce
5886228..82bf299 master -> master
Branch master set up to track remote branch master from origin2.
pull拉取修改,更新本地
下载同步代码就是pull命令
git pull origin master
$ git pull origin master
From github.com:HubSKY/MapReduce
* branch master -> FETCH_HEAD
5886228..82bf299 master -> origin/master
Already up-to-date.
用gitshell管理很方便,git shell还包含分支创建,合并和删除等,这里就不一一细讲,以上这些命令就足够平常我们这些人使用了