克隆
git clone http://xxxxxxxxxxx/xxx.git](http://xxxxxxxxxxx/xxx.git
查看git状态
git status
创建新的分支
git branch newBranchName
切换分支
git checkout BranchName
删除分支
git branch -d BranchName
添加新文件
# . 表示所有新文件
git add .
# 添加某个文件
git add xxx.txt
提交
# -m参数表示提交信息
git commit -m "add xxx.txt file"
分支推到远程分支
# 先切换到 develop 分支, 再推送到 develop 分支
git push develop feature-discuss
查看提交记录
git log
查看所有分支
git branch -a
需要放弃本地的修改,用远程的库的内容就可以,应该如何做?
git fetch --all
git reset --hard origin/master
拉取远程分支并创建本地分支
git checkout -b 本地分支名x origin/远程分支名x
git checkout -b dev origin/dev
举一个例子
假设我是一名网站的开发者,已经把源仓库fork了,并且clone到了本地。
现在要开发网站的“讨论”功能。
我在本地仓库中可以这样做:
step 1: 切换到develop分支
git checkout develop
step 2: 分出一个功能性分支
git checkout -b feature-discuss
step 3: 在功能性分支上进行开发工作,多次commit,测试以后...
git commit -m "add icon"
...
git commit -m "add avatar"
step 4: 把做好的功能合并到develop中
# 先切换回develop 分支
git checkout develop
# 合并feature-discuss分支到develop分支
git merge --no-ff feature-discuss
删除功能性分支
git branch -d feature-discuss
把develop提交到自己的远程仓库中
git push origin develop
这样,就完成一次功能的开发和提交。
网友评论