初次使用git详细配置步骤及上传代码

来源:互联网 发布:ica算法matlab代码 编辑:程序博客网 时间:2024/05/16 12:45

一. git安装及github账号注册

1. git 安装

下载地址:https://git-for-windows.github.io/

2.github创建账号

https://github.com/ 

二. git初始化配置

Git安装成功后,打开Git Bash

1.设置user.name和user.email

$ git config --global user.name "你的用户名"$ git config --global user.email "你的邮箱"

2.生成SSH秘钥

C盘用户目录下,.ssh文件夹执行

$ ssh-keygen -t rsa -C "你的邮箱"

如果不设置密码,连续三个回车,最终.ssh文件夹下生成两个文件:

id_rsa
id_rsa.pub

3.添加秘钥

.ssh文件目录下执行

$ ssh-add id_rsa

如果报错:Could not open a connection to your authentication agent.
则先执行:

$  ssh-agent bash

之后再执行:

$ ssh-add id_rsa

则执行结果:

Identity added: id_rsa (id_rsa)

4. 登录github,配置ssh

点击用户头像位置,选择settings

左侧选择 SSH and GPG keys

选择 New SSH key

title: 自己起个名字
key: 复制你本地.ssh文件目录下id_rsa.pub的内容

点击 Add SSH key

5.测试配置结果

ssh -T git@github.com

会看到:

The authenticity of host 'github.com (192.30.255.112)' can't be established.RSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxx.Are you sure you want to continue connecting (yes/no)?

选择 yes

最终会提示:

Hi 你的用户名! You've successfully authenticated, but GitHub does not provide shell access.

至此,说明配置成功~~

三、开始使用github

1.github新建项目clone至本地

这种方式简单,直接git clone :

$ git  clone  xxxxxxx

2.本地新建项目上传至github

本地新建项目,提交至git

(1)本地新建项目目录

$ mrdir web-learning

(2)初始化git

$ cd web-learning$ git init

web-learning目录下会增加.git目录

(3)本地新增文件

新建文件index.html

查看当前目录所有还没有被git管理的文件和被git管理且被修改但还未提交的文件

$ git status

文件 名 红色 标出

$ git add index.html$ git status

之前红色的文件,变为绿色

(4)本地add的文件提交到仓库

$ git commit -m "本次commit的message"

(5)将本地仓库关联至远端

首先在github上新建repository, 然后copy新建仓库的git地址
将本地仓库与远端仓库关联:

$  git remote add origin xxxxxxxx

将已经commit的代码push到远端:

$ git push -u origin master

完成代码上传。
可以在github确认下。

原创粉丝点击