桜花树下

如何使用Git管理工具

Git 命令使用

git clone <repository_url> //克隆仓库

git init //初始化文件夹

git remote add origin ssh&url //连接远程仓库
git remote -v   //查看所有远程连接

git pull origin remote-branch --allow-unrelated-histories//同步远程仓库

git add ./<file>  //添加、提交更改到本地暂存区
git reset      //删除暂存区的内容
git commit -m "Your commit message"     // 将暂存区提交到本地分支

git push origin local-remote-branch (--force)//推送到远程仓库(分支名一致)

git push origin local-branch:remote-branch //将本地分支上传到远程仓库(分支名不一致)

对于他人的仓库,要先fork副本,,然后将本地分支push到副本分支,再pull request()
git revert HEAD    //撤销上一次提交
git branch branch_name  //创建新的本地分支
git checkout branch_name //切换到本地分支
git checkout -b local-branch-name  //创建新的本地分支并立即切换到该分支
git branch //列出所有的本地分支
git branch -d branch_name //删除本地分支
git fetch origin //重置本地分支到远程分支的状态