This is the sixth day of my participation in the November Gwen Challenge. See details: The Last Gwen Challenge 2021.

preface

In this article, I will teach you how to implement Github access configuration, complete their first Github project maintenance, as well as participate in open source projects, contribute their own code, follow the small egg to learn.

Helpful hints

If you are not familiar with git commands, or you are a git novice, you are advised to check out my Git column and get started easily.

Git column address: juejin.cn/column/7025…

Local Git implements Github access configuration

Create a Github account

If you haven’t used Github yet, you’ll need to visit Github.com first (since it’s an external address, it can be very slow to access, don’t panic, follow me, I’ve prepared a quick access tool for you, you get the idea).

Configuring an SSH Public Key

Pull code from Github can be pulled over HTTPS or SSH

In SSH mode, you need to configure the SSH public key

Start by creating a public key

Click on the profile picture in the upper right corner of Github, select Settings, and click SSH and GPG keys on the left

I’ve created SSH keys before, and you can create multiple SSH keys,

Git key = git key = git key = git key

Local key creation

Type some commands on the command line of our computer

SSH directory % CD ~/. SSH // Check whether the key is configured. % ls id_rsa id_rsa.pub known_hostsCopy the code

Here I have configured the key before, and I will tell you about these files first:

  • Id_rsa: private key corresponding to public key
  • Id_rsa. pub: This is the public key, and this is what we will configure on Github later

Normally we don’t create a key locally, so let’s create a secret key

Create a secret key:

% ssh-keygen -t rsa -C "[email protected]" 
% ls
id_rsa    id_rsa.pub  known_hosts
Copy the code

This step is all it takes to create your own key

Let’s take a look at id_rsa.pub:

% cat id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCsHMsBfRmN2lVOpfL+NsBsM8KmH0NLQjh/3H2R+EzovYR0RxwsgWmioql9LQTu30HYJOjmSO9LCteEPCRadsdasd3h H3AL/6affadsUkLBAwTXvtz1grUhrz3PWwqsdKaffasfasashWAKvUbhW0fOl6lLQRJZbyPrctovOQsHlH44SHy3/d3AjmQxj9VWp/1xXdsdasdasdasdxZE 4rY4cyok3//0b+9nH00qxadafafviFmDC601jjxKG898DyeuGt7oseJfbLgpUuHgCg9AknlFty/eP/pipadnRXnikHOCMkXrpW9qIXcieEmdQMBvw3LeI4US bxFvT1V/TaQOowda8vCffK96QSpTYVZhDLbsyViTzriE0c8hwIot+8hmzrFXadadsaadsdasasdmtUfubOs6TnchIfp+hb/bmEP7GrpuDctV5tlWmaOfLJpx zy271oaSvZcAGZiClMWvJhDbSDg4eYojJlnNlG7+lfDtFc1moTrRoBxv57AWVj0OV44e/PRMhJZhwTN26W/LLp3bKJz7C8= [email protected]Copy the code

As you can see, inside is an encryption string, and this encryption string is the key we need to configure in github.

This completes our SSH configuration so that early code can be pulled and committed locally, either over HTTPS or SSH.

How do I maintain my projects

If we want to host the project on Github, the first step is to create a repository on Github

Creating a warehouse is actually very simple, fill in your warehouse name, and description, and another is to choose whether your warehouse is public or private, if you choose public so that everyone can see your warehouse.

Once the repository is created, we can pull the repository for local development

% git clone [email protected]:lrlr/git_learning.git
Copy the code

Here, I choose the CLONE project in SSH mode, and then we can submit and pull the code based on this warehouse.

How do I contribute code to open source projects

If you want to participate in an item but don’t have push permission, you can “spawn” that item. The derivative means that GitHub will create a copy of your project in your space that you can push.

Previously, “fork” was a pejorative term, referring to someone pushing an open source project in a different direction, or creating a rival project that split the original project’s contributors. On GitHub, “fork” refers to a copy of a project created in your own space that allows you to modify it in a more open way.

After forking, we can push changes to a derived copy of the project and get their changes into the source repository by creating a Pull Request. The usual operation process is as follows:

  1. Clone the project from fork after the project copy
  2. Commit some changes to improve the project
  3. Push the branch to GitHub
  4. Create a merge request
  5. Discussion, according to the actual situation continue to modify
  6. The project owner merges or closes your merge request

Here I’ll actually do it:

Let’s say I look at an open source project

Fork it down

After fork we pull it and modify the commit:

// clone project % git clone [email protected]: LRLR /java.git commit % git commit -a -m 'want to merge' % git pushCopy the code

Now go to GitHub and look at the previous project copy. GitHub informs us that we have a new branch and can click Contribute when we want to merge into the original repository of the open source project

When you click the “Create Pull Request” button, the project owner will be alerted with a link to the change and merge request page. Your request will then be processed

If you are not familiar with git commands, you can check out my previous git articles.