当前位置:首页 > Windows程序 > 正文

看我一步步入门(Windows Git Bash)

2021-03-29 Windows程序

    不同的版本控制工具的比较这里就不介绍了,我的入门是从windows开始的,而且是使用纯命令方式(Git Bash),当然也可以结合TortoiseGit或者msysgit中的GIT Gui工具,这个工具可以通过界面方式来操作管理。

    我们要管理项目,首先要建立一个GIT服务器系统,来管理项目版本。但是有的条件有限,我们搞不起服务器,只能借助第三方了,github就是很好的选择,它是一个网站,已经部署好了GIT系统,我们只需要注册个账号,然后就可以免费当我们的GIT服务器了,作为开发项目托管,msysgit是GIT版本控制系统在windows下的开源版本,在Linux系统下我们需要编译安装git。

    开始学习之前,需要对一些概念要理解,比如仓库,分支啊啥的,不过不理解没关系,在实践的过程中我们慢慢就会懂了。不懂的概念要学会去找资料了解,遇到的问题不要放过,要解决。相信很快就可以入手了!

    下面简单的说下github(remote)服务端和本地的关系,在本地可以独立建立仓库,并在本地管理,这就不需要接触到pull/push/fetch了,如果你想把项目托管到github,,则需要pull/push/fetch了。像个人开发的项目就可以不必利用github来托管,即不用GIT服务器系统。

1 安装

    下载地址:----git for windows VERSION 1.9.5

2 配置

GIT中文乱码

    D:\Program Files (x86)\Git\etc中的git-completion.bash文件最后一行加上(重新打开bash才有效):

    echo "alias ls=‘ls --show-control-chars --color=auto‘" >> git-completion.bash

在GIT终端输入下面的命令可以提高GIT的输出格式

    git config --global color.branch auto

    git config --global color.diff auto

    git config --global color.interactive auto

    git config --global color.status auto

设置你的名字和email,这些是在提交commit时的签名

$ git config --global user.name "FreeApe"

$ git config --global user.email "FreeApe@aliyun.com"

设置完名字和email后,会在主目录里新建了一个全局的配置文件.gitconfig,如果不用全局设置,则在上一步中不用加--global参数,然后会在当前项目中的.git/config文件增加了以上的设置内容

$ cat .gitconfig

[user]

       name = FreeApe

       email = freeape@aliyun.com

当不用global时只是对当前项目进行设置,如warning: LF will be replaced by CRLF...出现是因为默认换行符为Linux系统下,为LF,而windows下的换行符是不一样的,为CRLF。出现这个警告,我们可以对项目进行设置(可以加--global):

$ git config core.autocrlf false

SSH Key生成及github上添加SSH Key(一种不需要密码,用于受信的电脑,有点类似淘宝证书之类的)

检查电脑上是否已有SSH Key,有的话会列出所有.pub文件,重新生成的话可以删除它们

$ ls -al ~/.ssh

产生一个新的SSH Key

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Generating public/private rsa key pair.

Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

Enter passphrase (empty for no passphrase): [Type a passphrase]不输入密码的话则为空密码

Enter same passphrase again: [Type passphrase again]

Your identification has been saved in /Users/you/.ssh/id_rsa.

Your public key has been saved in /Users/you/.ssh/id_rsa.pub.

The key fingerprint is:

01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com

添加SSH Key到ssh-agent

$ ssh-agent -s  

#启动ssh-agent 到后台

Agent pid 59566

$ ssh-add ~/.ssh/id_rsa

Could not open a connection to your authentication agent.???

添加SSH Key 到你的账户

$ clip < ~/.ssh/id_rsa.pub

#复制id_rsa.pub文件内容到黏贴板

然后将复制的内容黏贴到github.com上的账户中的Setting中的SSH Keys中。

测试连接

$ ssh -T git@github.com

The authenticity of host ‘github.com (207.97.227.239)‘ can‘t be established.

# RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.

# Are you sure you want to continue connecting (yes/no)?选择yes

Hi username! You‘ve successfully authenticated, but GitHub does not

# provide shell access.如果username为你的账户名,则测试连接成功。

3 操作

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/69900.html