Git常用操作命令

新建代码库

当前目录新建代码库 git init

新建一个目录,将其初始化为git代码库 git init [project-name]

下载一个目录git clone [url]

配置

显示当前的git的配置 git config --list

编辑git的配置文件 git config -e [--global]

设置提交代码时的用户信息

git config [--global] user.name "[name]"

git config [--global] user.email "[email address]"

增加/删除文件

添加文件到暂存区 git add [file1] [file2]

添加指定目录到暂存区 git add [dir]

添加当前目录的所有文件到暂存区 git add .

删除工作区文件,并且将这次删除放入暂存区 git rm [file1] [file2]

改名文件,并且将这个改名放入暂存区 git mv [file-original] [file-renamed]

代码提交

提交暂存区到仓库 git commit -m [message]

提交暂存区的指定文件到仓库区 git commit [file1] [file2] .. -m [message]

提交工作区自上次commit之后的变化,直接到仓库区 git commit -a

提交时显示所有不同的信息 git commit -v

分支

列出所有本地分支 git branch

列出所有远程分支 git branch -r

列出所有本次分支和远程分支 gir branch -a

新建一个分支,但依然停留在当前分支 git branch [branch-name]

新建一个分支,并且切换到该分支 git checkout -b [branch]

删除分支 git branch -d [branch-name]

删除远程分支

git push origin --delete [branch-name]

git branch -dr [remote/branch]

 

远程同步

下载远程仓库中的变动 git fetch [remote]

显示所有远程仓库 git remote -v

显示某个远程仓库的信息 git remote show [remote]

增加一个新的远程仓库,并命名 git remote add [name] [url]

取回远程仓库的变化,并与本地分支合并 git pull [remote] [branch]

上传本地指定 分支到远程仓库 git push [remote] [branch]

强行推送当前分支到远程仓库,即使有冲突 git push [remote] --force

推送所有分支到远程仓库 git push [remote] --all 

本文原链接地址:http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html

 

posted @ 2016-10-27 11:43  DengPan  阅读(127)  评论(0编辑  收藏  举报