📜  如何链接 github - Shell-Bash (1)

📅  最后修改于: 2023-12-03 14:53:20.863000             🧑  作者: Mango

如何链接 Github - Shell/Bash

Github 是开源代码托管平台,也是程序员跟团队合作、管理项目的重要工具平台之一。在 Github 上创建自己的仓库并与之关联,方便管理自己的项目代码、代码版本控制等。本篇文章将介绍如何通过 Shell/Bash 命令行链接 Github。

步骤
注册 Github 账号

首先需要注册 Github 账号,如果已有账号可以忽略此步骤。

安装 Git

在命令行终端输入以下命令行安装 Git:

sudo apt-get update
sudo apt-get install git
配置 Git
  1. 配置用户名和邮箱:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
  1. 生成 SSH Key:
ssh-keygen -t rsa -b 4096 -C "your.email@example.com"
  1. 将 SSH Key 添加到 Github 账号中:

将生成的 SSH Key 添加到你的 Github 账号中。在 Github 页面的右上角中点击头像,选择 Settings -> SSH and GPG keys -> New SSH Key,将 SSH Key 填入 Key 中,保存即可。

创建并关联远程仓库
  1. 首先,在 Github 上创建远程仓库,获取仓库的地址,例如 git@github.com:your_username/repo_name.git

  2. 在命令行中进入你要上传的项目的根目录,并执行以下命令行:

git init
git add .
git commit -m "initial commit"
git remote add origin git@github.com:your_username/repo_name.git
git push -u origin master

其中 git init 是初始化本地仓库,git add . 添加所有文件到本地仓库,git commit -m "initial commit"提交本地仓库修改的代码,并添加提交信息,git remote add origin git@github.com:your_username/repo_name.git 将本地仓库与远程仓库建立联系,git push -u origin master 将本地仓库的代码推送到远程仓库上。

总结

以上就是如何通过 Shell/Bash 命令行链接 Github 的全部过程及方法。通过这种方式配置 Github,可以使程序员更方便地管理项目代码,也更有利于团队合作开发。