git 安装配置

在公网上使用git,在git的官方网站上下载git.zip文件

git的使用的时候需要首先创建于GITHUB连接的KEY

注册git账户和创建仓库
要想使用github第一步当然是注册github账号了, github官网地址:https://github.com/。 
之后就可以创建仓库了(免费用户只能建公共仓库),Create a New Repository,
填好名称后Create,之后会出现一些仓库的配置信息,这也是一个git的简单教程。

配置git

在本地创建ssh key
$ssh-keygen -t rsa -C "aouo1987@163.com"
    
邮箱为自己在githud上注册的邮箱,之后会要求确认和输入密码,我已一路回车下去。如果成功会在当前用目录下下生产.ssh文件夹。
然后进去打开id_rsa.pud,复制里面的key,回到githud的网站,进入账户设置页面,选择ssh keys,将key的信息黏贴进去
​
​
通过命令:$ssh git@githud.com进行验证是否配置成功
ssgao:.ssh aouo$ ssh git@github.com
PTY allocation request failed on channel 0
Hi aouo1987! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

git设置用户信息

接下来就是把我们的本地仓库传到githud上去,在此之前需要设置usernmae和email因为githud每次commit都会记录他们
​
$ git config --global user.name "your name"
$ git config --global user.email "your_email@youremail.com"
$ git remote add origin git@github.com:yourName/yourRepo.git
​
上面我们已经配置了user.name和user.email,实际上git还有很多可配置项
比如,让git显示颜色,会让命令输出看起来更醒目
$git config --global color.ui true
这样git会适当的显示不同的颜色

git配置别名

如果我们敲git st就表示 git status那就简单多了,当然这种偷懒的方法我们是极力赞成的
我们需要敲一行命令告诉git,以后 st就表示status:
 git config --global alias st status
$ git config --global alias.co checkout
$ git config --global alias.ci commit
$ git config --global alias.br branch
​
--global参数是全局参数,也就是这些命令在这台电脑的所有git仓库下都适用。
在撤销修改时,命令 git reset HEAD file可以把暂存区的修改撤销掉unstage,重新放回工作区。既然是一个unstage操作,就可以配置一个unstage的别名。
$ git config --global alias.unstage 'reset HEAD'
这样在敲入命令:
git unstage test.py
实际上执行的是
git reset HEAD test.py

git配置文件

每个仓库的git配置文件都放在 .git/config文件中
$ cat .git/config 
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = git@github.com:michaelliao/learngit.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[alias]
    last = log -1
​
别名就放在[alias]后面,要删除别名,直接把对应的行删掉就OK
当前用户的配置文件放在用户主目录下的一个隐藏文件.gitconfig中
$ cat .gitconfig
[alias]
    co = checkout
    ci = commit
    br = branch
    st = status
[user]
    name = Your Name
    email = your@email.com
原文地址:https://www.cnblogs.com/ssgao/p/8879852.html