Giter Site home page Giter Site logo

draft's Introduction

使用Git向OpenWHU/WHUCAO贡献资料

前言

本文将从命令行Git、Github Desktop两个不同的使用方式出发,简单讲述Git的基本工作流程,以使读者可以使用Git向OpenWHU/WHUCAO贡献资料

命令行Git

下载与安装

  • 前往Git - Downloads下载,选择您的系统并下载。对于大多数Windows用户来说,选择Standalone Installer下的64-bit Git for Windows Setup即可
  • 打开并安装。其中有部分详细设置,在此不详细描述。对于本教程而言,您可以一路选择Next最后·Install
  • 安装后,按下WindowsR+R键输入cmd后确认,在打开的命令行窗口中输入
git --version

​ 出现相关版本信息,即安装成功

image-20230520111227675

基础配置

  • 在命令行窗口输入
git config --global user.name "your name"

​ 进行全局的用户名配置,此用户名即为Commit的对外显示用户名

  • 在命令行窗口输入
git config --global user.email "[email protected]"

​ 进行全局的邮箱配置,此邮箱即为Commit的对外显示邮箱

Fork仓库并Clone到本地

Fork目标仓库(以OpenWHU仓库为例)

image-20230520121946660

​ 创建完成后,您就会进入在您的账户下的对应的拷贝仓库

​ 左上角显示的应是您的用户名/OpenWHU (Forked from xxx)

  • 在您的仓库中,单击Code,并在HTTPS选项卡中单击复制按钮

image-20230520123633849

Clone仓库到本地

  • 在您的电脑上希望存放仓库的文件夹*(没有就新建一个)空白处右键选择Git Bash Here(Win11需要点击“显示更多选项”)*

  • 输入

    git clone 将链接粘贴到这里

    将您的仓库克隆到本地*(右键选择Paste粘贴,或使用快捷键Shift+Insert)*

完成后,仓库便被Clone到本地,后续文件操作(增、删、改等)即在对应文件夹中进行

Add、Commit、Pull、Push

add是将文件的变更操作提交到暂存区

commit则是将目前暂存区的修改打包提交到本地代码库

pull则是同步远程代码库到本地代码库

push则是将本地的代码库同步到远程代码库(本文中为Github)

Add

文件的增删改操作需要使用add命令提交到暂存区

  • 使用以下命令添加所有修改、删除或新建的文件到暂存区
git add .
  • 使用以下命令提交指定文件更改到暂存区
git add filename.txt
  • 如果再次修改了在暂存区中的文件,可以通过以下命令进行更新
git add -u

Commit

使用Commit命令将暂存区的代码提交到本地版本库

  • 使用以下命令提交到本地版本库
git commit -m '这里填写修改说明'

Pull

本地的代码库可能未更新远程代码库的新文件,使用pull命令同步远程代码库到本地代码库

  • 使用以下命令同步远程代码库到本地代码库
git pull origin main

Push

一切修改完成后,使用Push命令将本地代码库同步到远程代码库

  • 将本地的提交同步给远程版本库
git push origin main

注:此操作会弹出Github的登录页面,请在相应页面登录;您也可使用配置ssh秘钥对进行登录,在本文中暂不讨论

提交PR

完成Push后,相应的文件操作便同步到了您的相应的Github仓库中

此时,您需要向源仓库提交Pull Request,申请将自己仓库中的修改内容同步到源仓库中

  • 打开您的仓库页面
  • 选择Contribute并点击Open Pull Request

image-20230520133216700

  • 完善相关信息,创建PR

image-20230520133403081

  • 创建完成后,等待管理员合并到主仓库即可

至此,您就成功上传文件到源仓库(本例为OpenWHU)

Github Desktop

相较于命令行,图形化操作界面更简便

下载与安装

  • 前往GitHub Desktop Download页面下载Github Desktop应用程
  • 安装完成后打开,进行登录
  • 登录完成后填写NameEmail信息,该信息即为Commit的对外显示信息

Fork仓库并Clone到本地

Fork目标仓库(以OpenWHU仓库为例)

image-20230520121946660

​ 创建完成后,您就会进入在您的账户下的对应的拷贝仓库

​ 左上角显示的应是您的用户名/OpenWHU (Forked from xxx)

Clone仓库到本地

  • 打开Github Desktop
  • 选择Clone a repository from the Internet...

image-20230520134839579

  • 选择对应仓库并更改存储位置(可选)

image-20230520135020461

  • clone完成后,选择To contribute to the parent project

image-20230520135135026

完成后,仓库便被Clone到本地,后续文件操作(增、删、改等)即在对应文件夹中进行

选择并提交文件修改

你在本地仓库文件夹中做的所有修改都会被记录

  • 选择需要提交的文件修改并Commit提交到本地版本库

image-20230520140916345

  • Commit完成后,点击Push origin将本地版本库同步到远程Github版本库

    image-20230520141247054

提交PR

完成Push后,相应的文件操作便同步到了您的相应的Github仓库中

此时,您需要向源仓库提交Pull Request,申请将自己仓库中的修改内容同步到源仓库中

  • 打开您的仓库页面
  • 选择Contribute并点击Open Pull Request

image-20230520133216700

  • 完善相关信息,创建PR

image-20230520133403081

  • 创建完成后,等待管理员合并到主仓库即可

至此,您就成功上传文件到源仓库(本例为OpenWHU)

draft's People

Contributors

tavin-fang avatar xixeen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.