本文讲解下git的使用,包括使用git上传项目工程到github,以及错误解决。git
sudo apt-get update sudo apt-get install git
sudo apt-get update sudo apt-get install build-essential libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
wget https://github.com/git/git/archive/v1.9.2.zip -O git.zip unzip git.zip cd git-*
make prefix=/usr/local all sudo make prefix=/usr/local install
make prefix=/usr/local all sudo make prefix=/usr/local install
git config --global user.name "Your Name" #名字随意 git config --global user.email "youremail@gmail.com"
#查看: git config --list #编辑配置信息: sudo vim ~/.gitconfig ##能够修改的地方 [user] name = Your Name email = youremail@domain.com
ssh-keygen -C 'you email address@gmail.com' -t rsa #会在 用户目录 ~/.ssh/ 下创建相应的密钥文件 #上传公钥 在 github.com 的界面中 选择右上角的 Account Settings,而后选择 SSH Public Keys ,选择新加。 Title 能够随便命名,Key 的内容拷贝自 ~/.ssh/id_rsa.pub 中的内容,完成后,能够再使用 #测试: ssh -v git@github.com 会返回提示信息: Hi wpeace1212! You've successfully authenticated, but GitHub does not provide shell access.
#所有增长: git add . #指定增长: git add filename #filename文件名
#提交全部 git commit -m "Initial Commit" -a #m表示message , -a 表示全部 #提交特定文件 git commit -m "Initial Commit" file #file表示特定文件
#创建远程分支:第一次须要作 git remote add origin https://github.com/wpeace1212/BlogSource.git #https://github.com/wpeace1212/BlogSource.git 为你的工程url #查看远程分支: git remote -v #提交你的代码:第二次提交时只要执行这条语句: git push origin master
#查看全部分支: git branch -a #新建新的分支 other git branch other #切换到other git checkout -b other #在分支上提交工做: git commit -m "other file" other #合并分支 git merge
git remote add origin https://github.com/wpeace1212/BlogSource.git 错误提示:fatal: remote origin already exists. #解决办法: git remote rm origin 再从新执行
git push origin master 错误提示:failed to push som refs to....... 解决办法1: git pull origin master git push origin master 解决办法2:强制解决; git pull git push --force origin master
来自一条小鲨鱼(rlovep.com)github