一. git软件安装
Ubuntu
sudo apt-get install git-core
二. 转到项目根目录
略
三. 初始化
配置身份
git config --global user.name "yourName" | git config --global user.email "yourEmail"
初始化仓库
git init
四. 添加提交本地代码
添加单个文件(夹)或多个文件(夹)
git add [theFileOrDirYouWantToAdd]
添加所有文件(夹)
git add .
提交
git commit -m "Description Info for this commit"
五. 提交到远程仓库(Github)
添加Github ssh秘钥
略
在Github创建空仓库
略
链接到远程仓库
git remote add origin [yourRemoteReposityURL]
将本地分支链接到远程分支
git branch --set-upstream-to=origin/master master
pull
git pull --allow-unrelated-histories origin master
推送到远程仓库master分支 (第一次)
git push -u origin master
推送到远程仓库master分支(非第一次)
git push orgin master
六. 其他命令
git
git status //view modified content
the meaning of the colors
red: not added
green: added but not committed
cancel the change which are not committed
git checkout FilePathWithExtensionName
view the versions which have been committed
git log
rollback
git reset --hard HEAD[^...] // the HEAD is stands for the current version. It stands for latest version if it's appended a '^'
OR
git reset --hard VersionID
view history actions
git reflog
create a branch
git branch BranchName
create and check to the branch
git checkout -b BranchName
view branch
git branch
merge branch
git merge BranchName
linking with remote repo
git remote add origin https://github.com/CQJTUWilliam/RemoteRepositoryName.git
sync to remote repo
git push -u origin master // for the first time
OR
git push origin master
remove the linking between local repo and remote repo
git remote rm origin