第一步:创建git仓库php
cd到你的本地项目根目录下,执行git命令python
git init git
第二步:去github上建立本身的Repository,建立完成后拿到建立的仓库的https地址github
第三步:将本地的仓库关联到github上sql
例如: git remote add origin https://github.com/dinphy-dev/sudamod_frameworks_base-oms.git
vim
第四步:将项目的全部文件添加到仓库中
git add .
若是想添加某个特定的文件,只需把.换成特定的文件名便可
bash
第五步:上传github以前,要先pull一下,执行以下命令:
git pull origin master
app
第六步:将add的文件commit到仓库
git commit -m "init commit"
post
第七步,也就是最后一步,上传代码到github远程仓库
git push -f origin master
执行完后,若是没有异常,等待执行完就上传成功了,中间可能会让你输入Username和Password,你只要输入github的帐号和密码就好了ui
Git 一些错误的解决方法
1. Pull is not possible because you have unmerged files.
症状:pull的时候
$ Git pull
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'
应该是由于local文件冲突了
解决方法:
1.pull会使用git merge致使冲突,须要将冲突的文件resolve掉
git add -u
git commit
git pull
2.若是想放弃本地的文件修改,可使用git reset --hard FETCH_HEAD,FETCH_HEAD表示上一次成功git pull以后造成的commit点。而后git pull.
注意:
git merge会造成MERGE-HEAD(FETCH-HEAD) 。git push会造成HEAD这样的引用。HEAD表明本地最近成功push后造成的引用。
就个人经验,有时候会莫名其妙地出现这种情况,并且Untracked files 还特别多(实际上本身可能只改了一两个文件),因此只好先保存好本身肯定作出的local的修改,而后用git reset --hard FETCH_HEAD回到上次成功pull以后的点,而后再pull就没有问题了
2.You are not currently on a branch.
症状:有一次pull的时候又出现冲突,这回用“git reset --hard FETCH_HEAD”方法都不行了,出现:
$ git pull
You are not currently on a branch, so I cannot use any
'branch.<branchname>.merge' in your configuration file.
Please specify which remote branch you want to use on the command
line and try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.
解决方法:
首先
git checkout -b temp
其次
git checkout master
便可恢复到master repository的状态,而后就能够pull了
在git bush 中使用命令:
git config --global http.postBuffer 524288000
由于git上传,限定一次push命令的buffer大小。
上传项目时,不要打开来,否则各类失败
拉取git项目到本地
1.打开终端,cd到本身想要存放项目的文件夹
cd 文件夹
2.输入git clone url ,url为你要拉取的项目地址
git clone url
3.项目拉取成功
若是改动后的项目要上传到github
1.git add 你改动后的文件,若是想要所有上传 git add .
git add .
2.执行git commit -m “要添加的注释”
git commit -m "注释"
3.git push 上传,可能会让你输入github帐号和密码按提示输入便可
git push
修改上传的用户名和密码
git config --global user.name "Your Name" git config --global user.email you@example.com
全局的经过vim ~/.gitconfig来查看
git config user.name "Your Name" git config user.email you@example.com
局部的经过当前路径下的 .git/config
文件来查看
也能够修改提交的用户名和Email:
git commit --amend --author='Your Name <you@example.com>'
git commit已提交的Author信息能够经过git log查看 git log