Original: itsOli @ front-end 10,000 hours this article was first published in the public number "front-end 10,000 hours" this article belongs to the author, without authorization, please do not reprint! This article is adapted from "sparrow" private pay column "front end | ten thousand hours from zero basis to easily obtain employment"Copy the code
❗ ️ ❗ ️ ❗ ️
The following link is the latest erratum to this articleGit and GitHub: Commit code + Team work
Use Git proficiently.Copy the code
Preface: in the previous “from zero basis to ease employment | Git and making: (1) the Git, making initial understanding, we understand the importance of version control, and the preliminary cognition to Git, making us the front end of the study and work will always be accompanied by a path.
Last time we learned how to clone an existing project from GitHub into a local repository. On the other hand, if we create a local repository first and the project is in progress, is it possible to push the repository to GitHub remotely?
There is also a question, since Git is the new age of distributed version control system, and GitHub is a software source hosting service platform for version control through Git. What about when we’re a team working on a multi-person development project?
Now, let’s get started and solve each one in the form of two tasks.
1 Create a local repository and push it to a remote repository
- ✅ task: create a local file on our computer to save the upcoming project test2, and then find a way to push the changes related to this local file to GitHub remote repository.
1.1 Step 1: Preparation
Create a named test2 on making warehouse, related operations view “from zero basis to ease employment | Git and making: (1) the Git, making early know”.
- Note: this was checked in the previous article, but in this task, we will not check the test2 repository. Because just like the English prompt — we want to push a repository that has been built locally on our computer to GitHub.
1.2 The second step is analysis
After clicking Create Repository, you will see some new prompts:
-
Note 1: Don’t be afraid of this interface, it doesn’t give us an error, it gives us some guidance on how to do it step by step. Note 1 here lets us create a local repository using the command line shown below, and then associate the remote repository step by step.
-
Note 2: This is to let us directly use the command line to push a local repository of our computer.
1.3 Step 3: Create test2 project locally on the computer
Following the official instructions in step 2, we create a new Test2 project locally on the computer. Open the terminal and enter the command:
mkdir test2
cd test2
Copy the code
1.4 Step 4: Initialization
Initialize this local test2 folder as a local repository:
git init
Copy the code
-
Note 1: After the test folder is created locally, be sure to locate the path to this folder.
-
Note 2: we can only initialize this folder after locating it, otherwise you will initialize the entire home directory as your local repository! Init is short for “initinal”. This command is used to initialize a local folder into a local repository.
-
Note 3: here.git is the best standard for checking local folders and local repositories.
1.5 Step 5: Add, delete, change and check files in the local warehouse
Git readme.md echo "git readme.md" > < span style = "box-sizing: border-boxCopy the code
- This is the Linux pipe command that imports the “here is our Git advanced test repository” string into
README.md
In the file.
1.6 Step 6: Commit locally
git add .
git commit -am "init"
Copy the code
1.7 Step 7: Establish connections
After step 6, we should be able to push to the remote repository. But who do we push push to? Although we created test2’s empty repository on GitHub in the first step, the two have nothing to do with each other so far. So, we need to connect with GitHub remotely and tell the previously empty repository where we want to push the local repository.
git remote add original [email protected]:oli-zhao/test2.git
Copy the code
-
Note 1: In this command, remote means remote; A. add B. add C. add D. add Original is the name we gave to the test2 remote repository (you can choose whatever you want); The following [email protected]:oli-zhao/test2.git is the URL given in the upper right corner of the GitHub interface in step 2. I named the remote repository “original” and the URL of the remote repository is [email protected]:oli-zhao/test2.git.
-
Note 2: This command pushes the changes submitted to the local repository in step 6 to our remote repository named Original. — What’s the original here? It is [email protected]:oli-zhao/test2.git. You can put this address directly on it, but because it is long and hard to remember, we give it a label called original.
1.8 Step 8, complete the test
Then refresh your GitHub screen and the screen in step 2 will now look like the following, which means we’re done:
1.9 Step 9: Make our project available for online preview
- Click Settings and scroll down from the newly opened screen until you see the following screen:
- After you select Master Branch and Save, you will see the following screen:
- Our project can be previewed online by clicking on this URL:
🏆 Summary: Mission accomplished, plus an Easter egg. In fact, our local warehouse can not only be pushed to GitHub platform, but also to other platforms that support Git (Sina Cloud, coding, etc.). For the same reason, put the urls given to you by these platforms in the same position as the URLS in step 7.
There are also two related commands you can practice:
Git remote remove git remote remove git remote remove Git remote set- URL Specifies the tag of the URL to be modified. New URL 3. Git remote rename specifies the name of the current tagCopy the code
2 Teamwork tool: Branch
- ✅ task: have a preliminary understanding of what branches are, what functions they have, and roughly know how to use them.
2.1 What are branches?
For example, we now develop a project with 3-5 engineers, and during the development process:
-
There is a new requirement to develop a new function. OK, let A develop it. The method is to pull a branch on the current master branch, and then a will develop on a branch;
-
The main project will continue to advance;
-
Suddenly there is a new requirement to develop another new function, OK, let B develop it. The method is also to pull a branch b on the current master branch, and then B develops on the branch B;
-
The main project will continue to advance;
-
When a is finished, the code on the A branch is older than the main master branch, but the functionality on the A branch is new. At this point, A only needs to merge his code into the trunk branch, and the trunk master branch has both the latest code and the new functionality developed by A;
-
Similarly, when B is finished, it will do the same;
-
At the end of the project, the trunk branch master will have the latest code and new functionality to meet the new requirements.
🏆 summary: the above is the role of branches, if there is no branch, then only until the development of A, B can develop, otherwise it will be a complete mess!
2.2 How to use branches?
In a real world work scenario, teamwork relies more on branching than anything else. One of the most powerful aspects of Git compared to SVN is its powerful “branch”.
2.2.1 Creating a local library Develop branch
(❗️ develop is the name you give to the branch, you can take any ~)
git branch develop
Copy the code
※ Push the “Develop branch” of the local repository to the “Develop branch” of the remote repository
Git push original develop:develop ❗️Copy the code
2.2.3 Switch to the Develop branch
git checkout develop
Copy the code
2.2.4 Develop the project in this branch and submit it to the local warehouse branch
touch a.md
git add .
git commit -am "a.md"
Copy the code
2.2.5 Push to the Develop branch of the remote repository
git push original develop
Copy the code
2.2.6 Merge the Develop branch with the master branch
- Switch to the master trunk branch:
git checkout master
Copy the code
- Merge all add, delete, change and check items from the Develop branch into the master:
git merge develop
Copy the code
2.2.7 Release online
Right now my code on the GitHub remote repository is still my code on the Master branch, only one copy.Copy the code
2.2.8 Pushing to the Remote Warehouse
git push original master
Copy the code
-
Note 1: At this point, open GitHub to see if test2 has added a branch with an a.d file.
-
Note 2: After this step is complete, refresh GitHub to see if test2’s master branch also has an a.d file and if the develop branch contains the same files as the master branch.
2.2.9 When conflicts are encountered
When you and someone else have changed the same file in the same place, we will execute:
git pull
Copy the code
Conflicts occur when updating the local merge. The solution is:
-
Modify trade-offs conflict files;
-
Resubmit.
Postscript: The above is the knowledge of version control and the application of related tools that we should grasp for beginners to learn the front end. In the following specific learning process of Web development, we will always have access to Git and GitHub.
After learning this article, we will formally start our static page development study – HTML, CSS, the corresponding knowledge point will be a lot of very miscellaneous, but full of fun, full of challenges.
I wish you good, QdyWXS ♥ you!