本文講解下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