Git笔记

Ubuntu怎么配置 git 和连接 github

1. 生成 ssh key

ssh-keygen -t rsa -b 4096 -C "youremail@xx.com"

这些可以全部按回车跳跃

Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
The key fingerprint is:

此时如果成功生成了 ssh key 文件的话,执行命令 ls -al ~/.ssh 会看到生成了文件 id_rsaid_rsa.pub

drwxr-xr-x 2 root root  101 May 21 18:14 .
drwx------ 1 root root 4096 May 18 15:49 ..
-rwxr-xr-x 1 root root   42 May 21 17:36 authorized_keys2
-rw------- 1 root root 3381 May 21 18:14 id_rsa
-rw-r--r-- 1 root root  742 May 21 18:14 id_rsa.pub
-rw-r--r-- 1 root root  444 May 21 18:08 known_hosts

2. 添加 SSH 密钥到 SSH 代理: 在生成 SSH 密钥后,需要将其添加到 SSH 代理中。运行以下命令:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

3. 将公钥添加到 GitHub 账户: 需要将生成的公钥添加到你的 GitHub 账户中。

cat ~/.ssh/id_rsa.pub

将这个命令输出的结果全部复制粘贴到 github 的账户中并保存。

4. 添加用户邮箱和姓名信息

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

5. 测试与 github 的连通性

ssh -T git@github.com

如果成功配置,执行之后会输出如下内容

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

上传项目到 github 仓库

  1. 创建 GitHub 仓库

    • 首先,在 GitHub 网站上登录您的账户。
    • 然后,点击页面右上角的加号图标,并选择 “New repository”。
    • 在新页面中,填写仓库的名称、描述以及其他选项,然后点击 “Create repository”。
  2. 将本地项目初始化为 Git 仓库

    • 打开终端,并导航到您的本地项目所在的目录。
    • 运行以下命令来初始化 Git 仓库:
      git init
      
  3. 将文件添加到暂存区

    • 使用 git add 命令将您要上传到仓库的文件添加到 Git 的暂存区。例如,如果要将所有文件添加到暂存区,可以运行:
      git add .
      
  4. 提交文件到本地仓库

    • 使用 git commit 命令将添加到暂存区的文件提交到本地仓库。在提交时,您需要提供一个提交消息,描述这次提交的内容。例如:
      git commit -m "Initial commit"
      
  5. 将本地仓库连接到 GitHub 仓库

    • 在 GitHub 仓库页面上找到 “Quick setup” 部分,并复制其中的远程仓库 URL。
  6. 将本地仓库与远程 GitHub 仓库关联

    • 运行以下命令,将本地仓库与远程 GitHub 仓库进行关联,并将其命名为 origin(您也可以选择其他名称):
      git remote add origin <远程仓库URL>
      
  7. 推送本地仓库到 GitHub

    • 最后,使用 git push 命令将本地仓库的内容推送到远程 GitHub 仓库。例如:
      git push origin main
      

    这里假设您的本地分支是 main,如果您使用的是其他分支,请将其替换为您的分支名称。

完成以上步骤后,您的本地项目应该已经成功上传到 GitHub 仓库中了。您可以在 GitHub 网站上查看并访问您的项目。

Windows怎么配置 git 和连接 github

配置 SSH keys

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值