`

Github使用总结(添加ssh-key,新建仓库,添加协作者)

    博客分类:
  • git
 
阅读更多

原文:Github使用总结(添加ssh-key,新建仓库,添加协作者)

 

 

今天为了把项目挂到Github上并且和组员协作好,研究了下Github的使用方法,现在做个总结记录下来。

1.添加ssh-key(该部分转自Github官网 https://help.github.com/articles/generating-ssh-keys

Step 1: Check for SSH keys

Have an existing keypair you'd like to use? You can skip to Step 4.

First, we need to check for existing ssh keys on your computer. Open up Terminal and run:

cd ~/.ssh# Checks to see if there is a directory named ".ssh" in your user directory

If it says "No such file or directory" skip to step 3. Otherwise continue to step 2.

Step 2: Backup and remove existing SSH keys

Since there is already an SSH directory you'll want to back the old one up and remove it:

ls# Lists all the subdirectories in the current directory
# config  id_rsa  id_rsa.pub  known_hosts

mkdir key_backup# Makes a subdirectory called "key_backup" in the current directory

cp id_rsa* key_backup# Copies the id_rsa keypair into key_backup

rm id_rsa*# Deletes the id_rsa keypair

Step 3: Generate a new SSH key

To generate a new SSH key, enter the code below. We want the default settings so when asked to enter a file in which to save the key, just press enter.

ssh-keygen -t rsa -C "your_email@example.com"# Creates a new ssh key using the provided email
# Generating public/private rsa key pair.
# Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

Now you need to enter a passphrase.

# Enter passphrase (empty for no passphrase): [Type a passphrase]
# Enter same passphrase again: [Type passphrase again]

Which should give you something like this:

# 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

Step 4: Add your SSH key to GitHub

Run the following code to copy the key to your clipboard.

pbcopy < ~/.ssh/id_rsa.pub# Copies the contents of the id_rsa.pub file to your clipboard

Be warned: it is important to copy the key exactly without adding newlines or whitespace. Thankfully the pbcopy command makes it easy to perform this setup perfectly.

  1. Go to your Account Settings
  2. Click "SSH Keys" in the left sidebar
  3. Click "Add SSH key"
  4. Paste your key into the "Key" field
  5. Click "Add key"
  6. Confirm the action by entering your GitHub password

Step 5: Test everything out

To make sure everything is working you'll now SSH to GitHub. When you do this, you will be asked to authenticate this action using your password, which for this purpose is the passphrase you created earlier. Don't change the git@github.com part. That's supposed to be there.

ssh -T git@github.com# Attempts to ssh to github

You may see this warning:

# 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)?

Don't worry, this is supposed to happen. Verify that the fingerprint matches the one here and type "yes".

# Hi username! You've successfully authenticated, but GitHub does not
# provide shell access.

If that username is correct, you've successfully set up your SSH key. Don't worry about the shell access thing, you don't want that anyway.

If you see "access denied" please consider using HTTPS instead of SSH. If you need SSH start atthese instructions for diagnosing the issue.


2.新建仓库

           2.1 在Github上登陆自己的账号点击右上方的Create New Repo


2.2 填写好自己的仓库名,(例如CSDNTest)

2.3Github上新建好仓库后在命令行运行如下指令(学过Git的应该知道是什么意思)

touch README.md git init git add README.md git commit -m "first commit" git remote add origin git@github.com:chenyl107/CSDNTest.git git push -u origin master
3.添加协作者

你的仓库-->setting-->Collaborators,然后输入你的协作者的用户名 add就可以了


 

分享到:
评论

相关推荐

    github101快速上手指南-beta.pdf

    上传代码到GitHub涉及一系列的Git命令,包括配置用户信息、克隆仓库、添加文件、提交更改、推送至远程仓库等。例如,通过`git config --global user.name "haoding"`和`git config --global user.email "fire9dingh@...

    github使用新手教程

    ### GitHub 使用新手教程 #### 一、GitHub基础知识与配置 **1. 登录GitHub账号** - 打开浏览器,访问GitHub官网([https://github.com](https://github.com)),输入您的用户名和密码进行登录。 **2. 创建组织**...

    Github使用教程、Github简介、安装、配置

    - **创建SSH Key**:使用`ssh-keygen`命令生成SSH密钥对,将公钥上传至GitHub个人设置中的SSH Keys,以便安全地连接GitHub。 - **验证连接**:使用`ssh -T git@github.com`命令检查是否成功连接GitHub。 - **设置...

    gitee使用方法.docx

    - 将公钥内容复制并粘贴到 Gitee 的 SSH Key 添加地址处。 - 完成后在终端测试 SSH 连接:对于 Gitee 使用 `$ ssh -T git@gitee.com`,对于 GitHub 使用 `$ ssh -T git@github.com`。 - 若连接成功,终端将显示...

    github教程 1

    在GitHub的“Settings”中,添加SSH Key,将公钥内容粘贴至Key文本框,即可实现本地与GitHub的身份验证。 接下来,我们将探讨如何在GitHub上创建远程仓库,并将其与本地仓库关联。在GitHub上新建仓库后,可以通过`...

    GitHub配置指南

    GitHub 是一个全球知名的开源代码托管平台,它允许开发者创建个人或团队的代码仓库,进行版本控制和协作开发。本文将详细介绍GitHub的基本配置步骤,包括创建账号、安装客户端、配置SSH Key、集成Eclipse以及项目的...

    github的使用

    本篇文章将基于提供的文件信息进行深入解析,旨在为初学者提供一份全面且易懂的GitHub使用指南。 #### 一、创建仓库 **步骤一:注册GitHub账户** 首先,你需要拥有一个GitHub账户。访问GitHub官网...

    github教程&常见问题解决方法&项目,GitHub使用思维导图.zip

    2. **SSH连接问题**: 如果出现"Permission denied (publickey)"错误,检查公钥是否已添加到GitHub账户,私钥是否正确配置。 3. **仓库权限问题**: 确保你有写入权限,如果没有,可以请求项目所有者添加你为贡献者或...

    如何将本地代码上传到github.pdf

    5. **添加远程仓库**:使用`git remote add origin &lt;你的GitHub仓库URL&gt;`命令将本地仓库与GitHub仓库关联。 6. **添加和提交文件**:通过`git add .`(或`git add &lt;file_name&gt;`指定文件)将文件添加到暂存区,然后...

    GitHub 常见操作和常见错误及其解决办法.docx

    在实际使用中,还会遇到如权限问题、SSH key 配置、Webhooks 设置等复杂情况,都需要逐步学习和掌握。 总之,熟悉 GitHub 的基本操作和错误处理是每个开发者必备的技能,这不仅可以提升个人工作效率,也有利于团队...

    git使用方式

    - 将新创建的文件添加到Git仓库中,可以使用命令: ```shell git add index.html ``` 这里以添加 `index.html` 文件为例。 **提交更改** - 提交已添加的文件到仓库: ```shell git commit -m "这是新建的...

    github-lecture

    【标题】:“GitHub 讲座” 【描述】:“GitHub 是一个全球最大...通过深入学习这些知识点,并结合“github-lecture-main”中的具体实例,无论是个人还是教育者,都能系统地掌握GitHub的使用,并能有效地传授给他人。

    TortoiseGit 使用教程.docx

    这通常涉及到 SSH Key 的生成、复制公钥内容以及将其添加到 Git 服务器的 SSH 设置中。 5. **TortoiseGit 常用操作** - **克隆**:右键点击资源管理器中的空白处,选择“TortoiseGit”-&gt; “Clone”,输入远程仓库...

    有关git的相关详细文档

    - 在使用Git之前,通常需要配置SSH Key以便于身份验证。具体步骤如下: - 打开命令行工具(如Git Bash),执行`ssh-keygen -t rsa -C "your_email@example.com"`生成SSH Key。 - 将生成的公钥内容复制到目标代码...

Global site tag (gtag.js) - Google Analytics