工作区
一个你存放代码的目录相当于一个工作区
版本库
在你的工作区中创建一个新仓库
git init
//将文件添加到暂存区(stage)
git add <file>
//将所有文件添加到暂存区(stage)
git add .
//提交到HEAD
git commit -m "代码提交信息"
//添加远程仓库地址
git remote add origin <url>
//提交到远程仓库,master是你要推送的分支
git push origin master
若出现此类错误
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/.../.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/.../.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
则可输入
//强制更新推送
git push --force <url>
分支
//列出分支
git branch
//列出分支(本地和远程仓库)
git branch -a
//建立分支
git branch <branch>
//切换分支
git checkout <branch>
//删除分支
git branch -d <branch>
//合并分支
git merge <branch>
//推送分支
git push origin <branch>
//删除远程分支
git push origin --delete <branchName>
其他命令
//删除远程仓库文件
git rm -r --cached <file>
git commit -m "注释"
git push origin master
//添加远程仓库地址
git remote add origin <url>
//修改远程仓库地址
git remote set-url origin <url>
//删除远程仓库地址
git remote rm origin
//删除本地仓库
rm -rf .git