Git is a version management tool that programmers use every day;

Github is the world’s largest programmer hub, hosting code and communicating with programmers.

Before getting ready to work on an open source project, we need to know some basics.

I hate writing this nonsense, but who knows git and Github? You want to say all that shit? But the beginning don’t write crap and does not know what to write, later can see how to write the hour you like crap to you see, actually the main reason for writing this article because dazed and confused not paying into an open source project development group, began also economist pack to force, chatting chatting found everyone is talent, listen and speak, that I myself, Vue3 is not 6, the code level is not as smooth as the big guys. Then you have to write git operation documentation to make a living. The most important thing is to let some people who can’t mention PR (myself a week ago) mention PR, so that I can attract more people to the group, and I won’t look so stupid ~ I’m really a smart guy!

Git basics

Basic nouns

branch

The git branch -a command is used to view all branches of your current project

In actual development, you often need to learn fromThe main branchCut toDevelopment branch, or inThe current branchCreate and switch to another templateThe new branch.

Git checkout -b dev// create the dev branch for the templateCopy the code

Git merge Git merge git merge git merge git merge git merge

Git merge dev // branch switch to masterCopy the code

Git rebase git rebase git rebase

Git rebase is a process that takes a set of commit records and places them on the target branch. Unlike a merge, git rebase’s commit history is a single line, rather than a tangle of branches. Git rebase is now recommended.

Here’s a practical example of the entire rebase process:

First of all, we havemasterBranches anddevEach branch changes and submits a file, and changes the same place to make the merge conflict, as shown in the figure: It is strongly recommended to just learngitGo download onegitThe graphics tool I’m using here issourcetree, you can just search and download it.)

Specific use methods are as follows:

Git rebase master // Switch to the master branch after the dev branch is committedCopy the code

If there is a conflict, the following message will be displayed:Fix the conflict and then do the following:

Git rebase --continue git rebase mergeCopy the code

After the operation is complete, we see that dev and master are now in a line

Git rebase dev, merge the master branch with the dev branch, and then push the master branch.

(A family is a neat family.)

Put a view after the merge operation, the contrast is the killer

Git reset –hard for rollback, git revert for rollback, git cherry-pick or git rebase-i for commit selection and merge. Or use git commit-amend to make a series of operations, such as submission information supplement is not detailed in the article, these operations can be in a strong strong strong strong recommend everyone has been to the git operation of the small game again, after a good earnings!

You count how many I used to strongly recommend this good website, from simple to deep with a small game through the way to let you learn git common and advanced operation, my cat after reading all straight call reliable!

Issue

Issue is a function to track and manage task and Issue assignments. When we submit the PullRequest, we will create an Issue at the same time, and they share the same ID. When committing code, you can interact with an Issue in the commit message.

First we create an Issue

We interacted with the Issue in the submission information at the time of commit

After the successful commit, we can find the code record of the commit in the corresponding Issue

We can also try other types of interaction, such as closing an Issue with a command

Let’s look at some of the basic instructions you need to use in other open source projects

Basic operation instruction

### git fetch

### git rebase

### git merge

git pull

Here some people ask :” Hey, you drew a cross in front of this why don’t you cross off, you write a small title and not write the content you are fooling people!”

In fact, git pull operation is a combination of the previous centralized operation, we use the common use of the following two commands:

git pull = git fetch + git merge
git pull --rebase = git fetch +git rebase
Copy the code

The git fetch command pulls the latest code from a remote repository to the local repository.

We’re throughgit fetchtheCAfter the submission is pulled to the local PC, it can passgit mergeorgit rebaseTo the currentdevBranch merges to the latestCAt nodes, the difference between the two has been described above and will not be repeated here.

Give an open source library a pullRequest (PR)

First of all, we need to know what a pullRequest is. A pullrequest is an action of making a change to the source code and asking the warehouse to adopt the change. After the PullRequest is sent, the administrator of the target warehouse can view the PullRequest and the code you changed, and everyone can add comments on your submission.

1. Fork project repository to participate in

Clone the code in your own repositories

You can choose HTTPS or SSH, depending on whether you have the key configured locallyAfter the code is pulled to the local, you can read the general structure of the code and the technology stack used according to your own knowledge reserve. If you don’t understand something, you can go to the group to ask the big guy. When you have a similar understanding of the project, you can try the first one in your lifepr.

The first step is to set up the upstream branch

git remote add upstream xxxxxx.git
Copy the code

Git branch -a can be used to view all associated branches after a successful setup

The purpose of setting up an upstream branch is to be able to pull code from the upstream repository directly locally, thus keeping the local code and the upstream repository up to date. For those of you who are a little confused about upstream branches, remote branches, and local branches, look at this diagram below.

(The soul artist makes a fool of himself)

The upstream repository we set up is actually the repository address of the project owner or project creator. Before each development, use the following command to pull the latest code from the upstream branch.

The second step is to pull the latest code from the upstream branch

Git pull --rebase upstreamCopy the code

sourcetreeYou can see that the upstream repository has committed many times since I last submitted a PR to the upstream code, executedgit pullAfter that, the local code is out of sync with the remote branch, and we need to use the local branch to force updates to the remote branch. performgit push -fCommand to force an update to the remote repository. After the update, the branch looks like this:

At this point, all branches are up to date and can be happily developed for requirements. Of course, in the actual development, there is usually a local branch to carry out the development of requirements or bug repair, which is generally calledFeature branchSo that we can develop requirements while ensuring that we have a stable branch to release software, usually calledmasterDoing so has many advantages when using feature branchingPull RequestHave a more specific topic and let the other party know your intention to change the code, which can help improve the efficiency of code review.

What is the third step

Skip (ten thousand steps omitted)

Step 4 Initiate a Pull Request

Then go to our Git and launch a Pull Request

In the CompareChange phase, you can see what you submitted in the PR. Click on it to see the file comparison visually. After confirming that it is correct, you can create a PR

Edit the title and content of the submission. Different open source libraries have different editing formats to clarify the intention of the submission and facilitate the owner’s review.

And then you can go to the correspondingPRHave a discussion and let everyone know if there are any bugs or errors in your code

After owner approval, one is completedPRThe whole process of ~End and spend

Matters needing attention

  • At the time of submission, some items will be correctcommitYou can find the corresponding configuration specification in the packagejson of the corresponding project, for example:

It is configured in the project I submittedcommit-msg, usually can be incommitlint.config.jsFile to view the corresponding rules, if not according to the rules, thencommitAn error is reported and the commit is blocked.

  • Some repositories for submittedcommit messageThere will be additional requirements, such as incommit messageCannot appear inmergeOr even that one requirement is better than just onecommit message. At this point we can usegit rebase -iorgit commit --amendHelp us carry outcommitThe merger.Those who have demand can check it by themselvesgit rebase -iInstruction, for some there isgit logNeat freaks or people with terminal OCD can be really useful.
  • submitPRThis is not to say that you should wait until everything is developed before submitting it. In the actual development process, you should wait until all features are developedprIt is likely to require extensive modifications or even re-implementation after receiving design and implementation corrections. We can submit it earlierPRInclude team members in the discussion during code development. In order to prevent this development processPRIf they are merged by mistake, they can be distinguished by filling in the title with some team agreed names such as ‘ing’, ‘wip’, etc.
  • gitThere are a lot of related knowledge, including somehubInstructions,Travis CIThe use of peripheral supporting plug-ins. Now there is no demand, we can look for relevant information when there is demand.

Whisper something

Some time ago always feeling, a lot of things to learn! Vue2 didn’t learn enough, but VUe3 came out! React Fiber is not fully understood, React18 is coming soon! There are some server-side Nodes with Node frameworks on top of Node, hybrid development, applets, and their native frameworks on top of frameworks and frameworks on top of frameworks! Sometimes go to interview, interview also test HTTP, network security, algorithm, disorderly 7 8 miscellaneous a lot!

However, when I calm down and think about it, LOOKING back at my working life in the past few years, I have some thoughts that I would like to share with you:

1. Is there anything you really need to learn? Are some technology stacks worth the time and expense of learning? The front end changes quickly, the technology changes quickly, some things have been quietly eliminated before you understand, really after learning the lifelong benefit should be the foundation to use some terms in the front end field to describe the so-called foundation, I think is JS, CSS, HTML, computer network, algorithm and so on. In other words, The bricks that make up the edifice at the front. The framework is to use these bricks to build up a small room, at the time of learning, we can’t only focus on the level of the API to learn a framework for what you want to learn is the framework for bricks, in what way the bricks combined together, I think, this is the important things, is worth we take time to learn!

2. Some time ago, I saw a public account wrote a story about front-end programmers, I feel very pleased, here are his conclusions:

Limited time, try as much as you can. Don’t put limits on yourself

The identity you choose matters, and your career success will ultimately be defined not by what you know now, but by what you can learn in 40 years or more

I think it is very reasonable, living in such a labeling era, programmer this label has a lot of meme, we don’t stick to their front-end programmers, React programmers, small program developers and so on these labels, don’t think of limiting yourself, first open your mind, the pattern can be big! (Came up with some memes and posted them for everyone to see)

3. Introversion. I think the phenomenon of introversion has always existed, but suddenly a word can accurately describe this phenomenon. Until the word “inner coil” came out, people thought it was interesting, and then they became active in various communities of migrant workers with Liping. I think you still have to be more interesting than yourself. I call it the salute. Ask yourself each day, ‘Are you more knowledgeable today? If the answer is yes, great, you’re stronger. If the answer is no, that’s fine, you just lost to the person you were yesterday! If you can play the self roll skillfully, but also afraid of the inside roll? You roll yours, I’ll roll mine!

There is no fourth point, an article about git operation writing so much bullshit does not know what you are thinking. If this is put in the exam essay, this kind of writing has zero points off the topic. Put the articles and related projects cited in this article below and see for yourself if you are interested.

Varlet – a component library developed by VUE3.

Here is a link to the book. If you need it, you can find the electronic version or buy the hard copy.