My First GitHub Project: From a Local Folder to GitHub Using Git and SSH

My First GitHub Project: From a Local Folder to GitHub Using Git and SSH

我的第一个 GitHub 项目:使用 Git 和 SSH 将本地文件夹上传至 GitHub

Getting your folder or file to GitHub can be a bit of an off vibe due to the many steps especially if it’s your first commit, but getting these steps right will make it easy for the other folders or files you will push afterwards. Let’s dive in. 将文件夹或文件上传到 GitHub 可能会因为步骤繁琐而让人感到困惑,尤其是对于第一次提交代码的人来说。但只要掌握了这些步骤,后续上传其他文件夹或文件就会变得非常简单。让我们开始吧。

CREATING A LOCAL FOLDER

创建本地文件夹

Depending on the OS you are using you can use Git Bash or the Terminal. For Linux which is what I am using I will use the Terminal. First Step: Start by creating a folder in the terminal: mkdir your_project_folder_name. Then change directory: cd ~/to_the_folder_you_have_just_created. 根据你使用的操作系统,你可以使用 Git Bash 或终端。由于我使用的是 Linux,我将使用终端。第一步:在终端中创建一个文件夹:mkdir 你的项目文件夹名称。然后切换目录:cd ~/你刚刚创建的文件夹路径

Now we need to format our folder by creating a few files inside it: Data file, README.md, and a code file if you will be using code. To check if you have created these files inside your folder, run: ls. This calls out all the files that are inside your folder. 现在我们需要通过在文件夹内创建几个文件来构建项目结构:数据文件、README.md,以及如果你要写代码的话,还需要一个代码文件。要检查这些文件是否已创建,请运行:ls。这会列出文件夹内的所有文件。

Data Folder

数据文件夹

Run command: mkdir data. This creates a data folder. This is where you will add your data e.g. Excel or CSV files that you will be using to run your analysis or your project. 运行命令:mkdir data。这将创建一个数据文件夹。你可以在这里添加数据,例如用于分析或项目运行的 Excel 或 CSV 文件。

README.md

README.md 文件

Run command: touch README.md. This is where you will give an overview of your work, the reason you are doing the analysis, how you collected your data, the tools you used to run the analysis… Basically, README.md is a file that guides anyone who goes through your analysis or project on the steps you took while doing your analysis or project. Think of it as the introduction at the start of your favourite book or novel. 运行命令:touch README.md。在这里,你需要概述你的工作、进行分析的原因、数据收集方式、所使用的分析工具等。简单来说,README.md 是一个向查看你项目的人介绍分析过程的指南。你可以把它想象成你最喜欢的书或小说开头的序言。

To write all of this you will run the command: echo "#give your project a name or describe your project" > README.md. README.md uses markdown language, which is the reason for the # at the beginning of the quotation. When writing the headings or subtitles use capital letters or proper style. For subtitles you need to add two ## at the beginning. 要写入这些内容,请运行命令:echo "#给你的项目起个名字或描述你的项目" > README.md。README.md 使用 Markdown 语言,这就是引号开头使用 # 的原因。编写标题或副标题时,请使用大写字母或规范格式。对于副标题,你需要在开头添加两个 ##

If you want to write more content without overwriting what you have previously written inside the README.md file you will need to use double greater signs (>>) at the end of the quotation, run: echo "#your message" >> README.md. Run cat README.md to check what you have written. If you made an error, run nano README.md - then edit. To save your changes - Ctrl+O then enter, Ctrl+X to exit. 如果你想添加更多内容而不覆盖 README.md 中已有的内容,则需要在引号末尾使用双大于号 (>>),运行:echo "#你的信息" >> README.md。运行 cat README.md 查看你写入的内容。如果出错,运行 nano README.md 进行编辑。保存更改:按 Ctrl+O 然后回车,按 Ctrl+X 退出。

Pushing Folder Or File To GitHub

将文件夹或文件推送到 GitHub

After creating our folder and files, we need to commit and push them to GitHub. For this process, you will need to have set up your GitHub account plus your SSH key. 创建好文件夹和文件后,我们需要提交并将其推送到 GitHub。在此过程中,你需要确保已设置好 GitHub 账户以及 SSH 密钥。

The first step we need to do is run git init. This initializes Git to start tracking all changes in the current folder. While running this command make sure you are inside the folder you want to commit. So change the directory into the folder or file you want to commit. 第一步是运行 git init。这会初始化 Git,开始跟踪当前文件夹中的所有更改。运行此命令时,请确保你位于要提交的文件夹内。因此,请先切换到你要提交的文件夹或文件目录。

Second step, run: git status. This shows all changes which were not committed yet. 第二步,运行:git status。这会显示所有尚未提交的更改。

Third step, run: git add .. This picks all the files in the folder. If you don’t want to commit the whole folder you can run: git add (the name of the file inside your folder that you want to commit). 第三步,运行:git add .。这会选中文件夹中的所有文件。如果你不想提交整个文件夹,可以运行:git add (你想提交的文件名)

Fourth step, run: git commit -m "(add message here of what you are committing or the name of the folder you are committing)". 第四步,运行:git commit -m "(在此处添加提交信息,说明你正在提交的内容或文件夹名称)"

Before pushing your folder, confirm if you are on the main branch by running: git branch. If it does not show main, switch to main by running git checkout main. 在推送文件夹之前,通过运行 git branch 确认你是否在 main 分支上。如果显示的不是 main,请通过运行 git checkout main 切换到 main 分支。

After you have successfully run all the steps above, now it’s time to push your folder to GitHub. Open your GitHub account, navigate to the repository on your far left, click on “New Repository”. Name your repository, this could be the same name as your folder, then give a brief clear description of your project, then press “Create Repository”. Note: do not add README.md since we already created one. 成功运行上述所有步骤后,现在是时候将文件夹推送到 GitHub 了。打开你的 GitHub 账户,导航到左侧的仓库列表,点击“New Repository”。为你的仓库命名(可以与文件夹名称相同),提供简明扼要的项目描述,然后点击“Create Repository”。注意:不要勾选添加 README.md,因为我们已经创建了一个。

Once it has been created, copy the SSH URL. After copying the URL, go back to the terminal and run: git remote add origin <your copied URL> (this is where you paste the URL you copied from GitHub), then run: git push -u origin main. 创建完成后,复制 SSH URL。复制 URL 后,回到终端并运行:git remote add origin <你复制的 URL>(在此处粘贴你从 GitHub 复制的 URL),然后运行:git push -u origin main

A prompt may appear if your SSH key has a passphrase, enter the passphrase. This is the passphrase you set when you were generating your SSH key. Go back and refresh your GitHub page, this should make the changes reflect on your GitHub page. Following these steps without skipping will get your project fully running on GitHub :) 如果你的 SSH 密钥有密码短语,可能会出现提示,请输入该密码短语。这是你在生成 SSH 密钥时设置的密码。回到 GitHub 页面并刷新,更改应该就会显示在你的 GitHub 页面上了。按照这些步骤操作,不要跳过任何一步,你的项目就能成功在 GitHub 上运行了 :)