简易的命令行入门教程:
git config --global user.name "zheng"
git config --global user.email "yangzhengwei5@qq.com"
创建 git 仓库:
mkdir vueDemoStudy
cd vueDemoStudy
git init
touch README.md
git add README.md
git commit -m "first commit" # 提交
git remote add origin # 添加指定远程仓库地址 (推送至指定远程仓库 )
git push -u origin master # 推送代码
已有仓库?
cd existing_git_repo
git remote add origin https://gitee.com/yang958/vueDemoStudy.git
git push -u origin master
常用命令
一、分支操作
1 查看远程分支
git branch -a2 查看本地分支
git branch 3 切换分支
git checkout (分支名)
例:git checkout Y_1.04 合并分支
先切换到主分支
git checkout master
git merge (分支名)
例:git merge Y_1.05:创建分支
想要新建一个分支并同时切换到那个分支上,可以运行一个带有 -b 参数的
git checkout 命令:
例:
$ git checkout -b iss53
Switched to a new branch "iss53"
它是下面两条命令的简写:
$ git branch iss53
$ git checkout iss536:拉取远程分支
参考网址:http://blog.csdn.net/jtracydy/article/details/53174175
只拉取远程分支:
git fetch origin master
二、文件操作
1 提交修改文件
git add -A 提交所有变化 git add -u 提交被修改(modified)和被删除(deleted)文件,不包括新文件(new) git add . 提交新文件(new)和被修改(modified)文件,不包括被删除(deleted)文件
git add (文件名) 把index.php提交到 例: git add index.php2 添加文件修改说明
git commit -m " [备注说明] 新建 index.php"3 查看状态
git status;
三、仓库操作
1: 把代码推到远程仓库
git push origin master (推)
git pull origin master (拉)
2:远程仓库
查看远程仓库 : git remote
查看仓库地址 : git remote -v
3:删除远程库
命令 : git remote remove < 远程库名 >
示例 : git remote remove origin
4:添加远程库
命令 : git remote add < 远程库名 > < 远程库地址 >
例 :
git remote add origin
注 : 远程库名一般叫origin , 但并非强制 , 可以自己起名 .
例 :
git remote add online
5:修改远程库名称命令:git remote rename < 旧名称 > < 新名称 >
例 :
git remote rename online oschina