📜  如何使作业在 github 操作上同步运行 - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:08:16.737000             🧑  作者: Mango

如何使作业在 Github 操作上同步运行 - Shell-Bash

在程序员日常的开发过程中,使用 Github 进行代码的版本控制和团队协作是十分常见的操作。在开发过程中,经常需要在本地进行代码的修改和测试,然后将代码同步到 Github 上,以便与其他人进行共享和协作。本文将介绍如何在 Shell-Bash 环境下,实现将本地代码同步到 Github 上的操作。

1. 配置 Github SSH Key

首先需要进行 Github SSH Key 的配置,这样才能通过 SSH 协议与 Github 进行数据传输。

1.1 生成 SSH Key

在本地 Shell-Bash 环境下,运行以下命令生成 SSH Key:

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

其中 your_email@example.com 指的是你的邮箱地址,可以替换为自己的邮箱地址。按照提示输入文件保存路径和密码即可。

1.2 添加 SSH Key 到 Github

登录 Github,进入 Settings -> SSH and GPG keys -> New SSH key,将生成的公钥(即 id_rsa.pub 文件的内容)复制并粘贴到 Key 中。保存即可。

2. 在本地创建 Github 仓库

在本地环境下,运行以下命令创建 Github 仓库:

$ mkdir project
$ cd project
$ git init
$ touch README.md
$ git add README.md
$ git commit -m 'first commit'
$ git remote add origin git@github.com:your_username/your_repos.git
$ git push -u origin master

其中 your_usernameyour_repos 分别替换为自己的 Github 用户名和仓库名。

3. 在本地修改代码并同步到 Github

在本地修改代码后,需要将代码同步到 Github 上。运行以下命令可以实现这一功能:

$ git add .
$ git commit -m 'update'
$ git push

其中 . 表示将全部修改的内容添加到本次提交中,update 是对这次提交的描述,可以根据实际情况进行修改。在执行 git push 命令时,需要输入 Github 的用户名和密码。

4. 克隆 Github 仓库到本地

如果需要在另一台电脑上继续进行开发工作,可以通过克隆 Github 仓库到本地实现。运行以下命令即可:

$ git clone git@github.com:your_username/your_repos.git

其中 your_usernameyour_repos 分别替换为自己的 Github 用户名和仓库名。

结语

本文介绍了如何在 Shell-Bash 环境下,将本地代码同步到 Github 上。希望对程序员们在 Github 上进行代码管理时有所帮助。