您的位置:首页 > 运维架构 > Shell

第一次使用 gitbash

2016-01-04 12:09 447 查看
此方法是自己开发时用的, 所以只有master一个分支

1. 安装gitbash. 下载地址: https://git-for-windows.github.io/.
2. 一些配置(可跳过)
http://blog.csdn.net/u011526234/article/details/50352135
3. 注册 github 账号,

4并添加私钥.(可查看网站文档或自行百度)

配置 SSH KEYS

要使用SSH协议连接 GITHUB,首先需要生成 SSH KEYS。生成的密钥是两个文件,一个公钥一个私钥。公钥需要提交给GITHUB 官网您的账号中。关于如何生成 SSH Keys,请看如下步骤示例:

检查 SSH keys

$ ls -al ~/.ssh

# Lists the files in your .ssh directory, if they exist

生成 keys

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

# Creates a new ssh key, using the provided email as a label

# Generating public/private rsa key pair.

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

然后按照提示输入密码,最后出现如下提示则说明生成成功。

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

# Your public key has been saved in /c/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 客户端

# start the ssh-agent in the background

$ ssh-agent -s

# Agent pid 59566

$ ssh-add ~/.ssh/id_rsa

复制公钥

复制公钥可以打开文件复制,也可以使用命令,建议使用命令复制,否则可能出现无法授权的问题。如下命令:

$ clip < ~/.ssh/id_rsa.pub

# Copies the contents of the id_rsa.pub file to your clipboard

将公钥加入到 GITHUB 账号

登录 GITHUB 在 Settings->SSH keys 菜单下添加,将剪切板的内容粘贴到 Key 文本框中,名称可以随意填写。到现在为止,配置工作已经完成。

5. 创建远程仓库.

https://github.com 中创建仓库()



6. 创建本地仓库并关联远程仓库(或者克隆远程仓库 git clone)

创建目录, 例如: f:/test,

使用 gitbash 进入test 目录, 执行命令 git init , 初始化仓库.

关联远程仓库, git remote add origin xxx(仓库地址)

添加文件, git add -A (全部添加) 添加指定文件, git add text.txt

本地提交: git commit -m "注释"

推送到远程仓库: git push -u origin master

由于远程库是空的,我们第一次推送master分支时,加上了-u参数,Git不但会把本地的master分支内容推送的远程新的master分支,还会把本地的master分支和远程的master分支关联起来,在以后的推送或者拉取时就可以简化命令。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: