一、git基本配置 1.安装git https://my.oschina.net/u/2988360/blog/796230 2.设置全局变量 git config --global user.nam
一、git基本配置
1.安装git
https://my.oschina.net/u/2988360/blog/796230
2.设置全局变量
git config --global user.name "Administrator"git config --global user.email "[email protected]"
3.创建rsa公钥与密钥对
$ ssh-keygen -t rsa -C "[email protected]"Generating public/private rsa key pair.Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):/c/Users/Administrator/.ssh/id_rsa already exists.Overwrite (y/n)? yEnter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.The key fingerprint is:SHA256:19IVqI0wgtyGiUmtXQOT4OMRFbuT5SQKoVPR9cgFPps [email protected] key's randomart image is:+---[RSA 2048]----+|..*X=Xo.. .. ||.+o.O=*+o . . ||+ +oooBo.o + . || +.+.B + oo.. || o + E S o o || . . . || || || |+----[SHA256]-----+Administrator@PC201607151815 MINGW32 /e/company_git_project (master)
4.进入.ssh目录,查看公钥内容
Administrator@PC201607151815 MINGW32 /e/company_git_project (master)$ cd /c/Users/Administrator/.sshAdministrator@PC201607151815 MINGW32 ~/.ssh (master)$ lsid_rsa id_rsa.pub known_hostsAdministrator@PC201607151815 MINGW32 ~/.ssh (master)$ cat id_rsa.pubssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7pJnPavedODSfY8p4PjtjmuIRDvschMYsP+8vJO43NaRUopK7BJW5M/i5IMDVa41m5ELhJy+CHd78wCRMBgkYrwKafbQ0vm7hGs3Wd07FBfCqN+EWMPm35zrJtgAoe+yYD3jWgkAm0YoPuRDTV7y4wNk4ZMV9o5pk42PCuTBe0wYi/r7zax8SPmajYM1Etdzv4LZxJvGB6+92nfKgswAfHwB1FFswEl0XkUUyLehUeO8FyPoltfFiUur2uckXf9sd/HyVyRmnDKIEENeeiEaRAIPtNHfzHEvBPDBf5/8tvWxtWldIoKd9vVI8ExZQffMT5k/4g0VywUAeTm2z6u/J [email protected]@PC201607151815 MINGW32 ~/.ssh (master)
5. 为当前登入用户导入公钥
6.选择文件目录,右键->Git Bash Here,得到命令操作窗口
7.远程下载git项目
Administrator@PC201607151815 MINGW32 ~/.ssh (master)$ git initInitialized empty Git repository in C:/Users/Administrator/.ssh/.git/Administrator@PC201607151815 MINGW32 ~/.ssh (master)$ git clone http://10.1.50.88/Zuogj/By-Bus.gitCloning into 'By-Bus'...
输入用户名密码后,从远程下载项目
二、代码上传与下载
1. 创建本地版本库
mkdir SmileCode
2.通过git init命令把这个目录变成Git可以管理的仓库
git init
3.本地仓库与远程版本库关联
4.提交代码,首次需要加上-u参数
三、命令行介绍
- Git 全局配置
git config --global user.name "Administrator"
git config --global user.email "[email protected]"
- 创建版本库
mkdir SmileCode #创建本地版本库
cd smilecode
git init #初始化本地版本库
git remote add origin [email protected]:Evaluation/EvaluationSystem.git
#将本地版本库与远程版本库关联
git add . #将文件添加到工作区
git commit -m "Initial commit" #将文件加入暂存区
git push -u origin master # 提交代码到远程仓库
git pull origin:表示,本地的当前分支自动与对应的origin主机”追踪分支”(remote-tracking branch)进行合并。
- 克隆远程库
git clone remote [email protected]:Evaluation/EvaluationSystem.git
-
只克隆git仓库中的一个分支
git clone -b <branch> <remote_repo>
如:git clone -b dev [email protected]:Zuogj/By-Bus.git
- 分支管理
查看分支:git branch
创建分支:git branch <name>
切换分支:git checkout <name>
创建+切换分支:git checkout -b <name>
合并某分支到当前分支:git merge <name>
删除分支:git branch -d <name>