Git的使用很简单,第一次在客户端获取代码时,直接经过各类IDE的clone方法,能够把Git上的工程get下来便可。后续使用时,新文件用 add、commit、push;获取新版本用 pull 或 fecth,遇到冲突就 merge 一下。
git
Git首次建立略麻烦。过程大体以下:
工具
在OSChina上建立Git项目。fetch
在本地装好 git 工具,安装好后,会有2个可执行文件,Git GUI 和 Git Bash ,正如名称同样,一个是GUI工具,一个是命令行工具。
spa
在本地项目的文件夹中(是否有文件均可以),右键菜单,执行 Git Bash,会进入命令行工具,自动定位在本目录下了。.net
进行初始化: git init命令行
添加当前全部文件: git add . ( . 表明目录下全部文件)ip
首次提交: git commit -m 'initial commit' ci
添加远程仓库: git remote add origin https://git.oschina.net/xxx/xxx.gitrem
提交远程前校对: git fetch origin masterget
提交远程前抓取: git pull origin master
将本地提交,推送到远程仓库: git push origin master
Ps. 若是报错:
报错信息:Updates were rejected because the tip of your current branch is behind,its remote counterpart. Integrate the remote changes (e.g. 'git pull ...') before pushing again.
解决方案:先执行 git branch --set-upstream master origin/master ,执行结果:Branch master set up to track remote branch master from origin. 而后再进入第8步。