Foreword: success is not in the future, but from the moment you decide to do, continue to accumulate. Hello, I am Mengyangchen, quickly with me to fix Git and Github.

The article directories

  • 01. Summary of Git
  • Git local repository operation
    • Git version rollback
  • 03. Remote warehouse
  • Git branch operations
  • 06. Conflict generation and resolution
  • 07.Git utilities
  • 08. Ignore files
  • 09.Github basic concept
  • 10. Github Pages



01. Summary of Git

1.Git is the most advanced in the world

distributed

Version control system.

Problems solved: Record each modification: version, content, user, modification time, document name, etc.

Git is a distributed version control system, simply said is a software, used to record one or more file content changes, in order to check the revision of a particular version of the software.

Github is a Git site for users, which is simply a place to put code (and other content). Github not only provides a web interface for managing Git, but also provides a variety of functions such as an online editor for subscription, following, and discussion groups.

Git does not have a central server like SVN.

Git commands are executed locally if you want to share your code with Git or collaborate with other developers. You need to put the data on a server that other developers can connect to. This example uses Github as the remote repository

The installation of the Git

Git local repository operation

1. Workflow

Git operates locally in three areas:



Workflow:

Temporary storage area: equivalent to shopping cart to store items to be purchased together with the final payment.

2. Local warehouse operation What is a warehouse? Git manages all files in the repository. Git can track every modification and deletion of a file in the repository.

Global configuration is required for first use after installation:

1. Click “Git Bash Here” to open the Git command line window:

$ git config --global user.name "Username"
$ git config --global user.email "Email address"
Copy the code

The user information is set up so that the user name is recorded when the project is modified

Create a repository whenever you need Git to manage a new/existing project.

It is recommended to use an empty directory to learn Git, because the operation error will cause unnecessary errors. Try to use English names for directory names.

3. Create a directory

$mkdir Specifies the directory nameCopy the code

It can also be created locally. 4. On the CLI, access the project directory pre_git

$ cdDirectory nameCopy the code

5. The initialization of a Git repository lets Git know that it is required to manage the directory

$ git init
Copy the code

After executing, open the project directory and click Hide directory to find a new.git folder. Can’t delete, also can’t change at will.

That’s where you can start developing. 6.Git common commands to check the current working status:

$ git status
Copy the code

What it does: When we forget where the project was, come back from a bathroom break, a meeting, etc. You can use this command to determine what to do next.

7. You can develop in the project directory

8. Add workspace file to cache:

Git add directive, you can add a file, can also add multiple files. $git add file name $git add file name 1 file name 2 file name 3...... $git add. $git add.Copy the code

9. Commit to version library

$ git commit -m "Comment content"
Copy the code

If a new file is created, repeat the above steps, starting with add.

If you modify the contents of the submitted file, you can resubmit it from add.

The commit and other operations here only commit to a Git local repository.

Git version rollback

The version rollback is divided into two steps: 1. First check the version and determine the point in time command to go back to:

$ git log
$ git log --pretty=oneline
Copy the code

The second instruction simplifies the message. 2. Rollback operation: Command:

$git reset --hard commit numberCopy the code

After the operation, the files in the project directory are returned to the specified time.

After going back to the past, what if I want to go back to the latest state? First: query the previous numbering instruction:

$ git reflog
Copy the code

And then execute

$git reset --hard commit numberCopy the code

Git reset –hard

Back to the future: You need to use git reflog to do a historical operation query to get the latest commit ID. (no.)

Git will automatically recognize the commit ID if it is not fully written. Write at least the first four digits.

03. Remote warehouse

The following uses Github as an example to describe how to operate an online warehouse. (There are many sites that provide remote repositories for Git repositories.)

1. Creation of Github online repository



2. Use an online warehouse

Add remote repository (add Github here)

In git bash, type CD /D in uppercase. If you do not enter this statement and do not locate git bash, the default local file location is on disk C. Then CD it to a folder with the same name as the remote repository.

1. Create an empty directory named shop (optional) 2. Copy the HTTPS pair due address. Then create a new shop directory in the current directory

$ mkdir shop
$ cd ./shop
Copy the code

3. Run the clone command to clone the online warehouse to the local computer.

$ git cloneOnline Warehouse addressCopy the code

When you clone an empty directory, only the hidden.git directory will be cloned.

4. After the preceding operations are complete, you can perform corresponding operations in the local warehouse

For example :(submit to staging area, submit to local warehouse, submit to online warehouse (remote warehouse), pull online warehouse) the previous operations are the same as the local warehouse operations above.

Then submit to the online warehouse:

If you are submitting for the first time, you should first get permission (otherwise you will get 403 error) because not everyone can submit to the online repository. Git /config file contents: in url: add: username: password @

Url = https://username: password @github.com/ Username/repository name.gitCopy the code

Everything else is the same.

Instruction: An instruction submitted to an online warehouse

$ git push
Copy the code

After successful submission, you will find that there is more content in the online repository than you have submitted.

Note: If you submit successfully after work: Colleagues also submit new content to the remote repository. The next day at work, you need to pull up the latest version of the warehouse online


Use the following command:

$ git pull 
Copy the code

So the first thing you do every day is pull the latest version of your Git pull line, and the next thing you do after work is commit your local code to an online repository.

The second method is based on SSH (recommended). Compared with HTTPS, this method only affects github’s user identification method, and does not change the specific operation of Git.

Procedure: 1. Generate the public and private key file of the client. 2. Upload the public key to Github.

Actual operation: 1. Create a public and private key file

The transfer between your local Git repository and GitHub repository is encrypted by SSH, so we need to configure the authentication information: generate an SSH Key using the following command:

Open Git Bash directly here :(you can also right click on your desktop to open it)

Then enter the command:

ssh-keygen -t rsa -C "Registered Email"
Copy the code

If you cannot generate the key (install OpenSSH yourself first) then execute the command above. Some tutorials on the web use commands:

$ ssh-keygen -t rsa-C "[email protected]"
Copy the code

Note: in fact [email protected] stands for registered email, that is, they are the same.

You will then be asked to confirm the path and enter the password, so we will use the default enter.

2. Locate the id_rsa.pub file. SSH folder will be generated under ~/. Go to id_rsa.pub and copy the key inside. Go back to Github and go to Account => Settings. To verify success, type the following command:

$ ssh -T [email protected]
Copy the code

Result: Hi XXXX! You’ve successfully authenticated, but GitHub does not provide shell access.

3. Create a local directory (for saving online items) and access the directory.

$mkdir Directory name $cd./ Directory name /Copy the code

Then clone the directory to the new directory:

$ git cloneSSH addressCopy the code

SSH and HTTPS addresses for online repositories can be found in Clone and Download 4. Follow-up operations are the same as HTTPS.

Compared to HTTPS, this method once configured, the future project does not need to configure the user name and password individually, can be said to be a one-time benefit. So this is recommended

Git branch operations

What is a branch?

That is, the branches of the project (different functions) :

All branches form a project.



In the version rollback, every commit is recorded, and Git strings them together into something like a timeline. This timeline is called a branch, which we call the Master branch.

Therefore, one branch cannot meet the needs of simultaneous development. Working on a branch does not affect the normal use of other branches, which is safer. Git encourages developers to use branches to complete some development tasks.

Branch instructions:

Git branch Create branch: git branch branch name Switch branch: git checkout branch name Delete branch: git branch-dGit merge Merge branch name git merge branch name git mergeCopy the code

Note: You can switch branches using the “git checkout -b branch name “command. The -b option means create and switch, which is equivalent to two operations.

* indicates the current branch.

So you can see that we’re all operating on branches.

Before deleting a branch, you need to exit the branch.

06. Conflict generation and resolution

1. After I got off work, my colleague modified the online project content, and the content of the local warehouse was inconsistent with that of the online warehouse. The next day, I forgot to do the Git pull operation and directly modified the local file. An error is reported when committing. 2. Run the “git pull” command to resolve the conflict.

3. Open the conflict file to resolve the conflict. Discuss what to save with the user who submitted the content. What to delete.

Then after resubmitting, we can do push operation.

This shows the importance of git pull before work.

07.Git utilities

1. Graphical management tools

Github for Desktop is a handy tool for developers who use Github regularly.

Source Tree Git GUI management tool for beginners.

TortoiseGit is very friendly for developers who are familiar with SVN. Its predecessor TortoiseSVN.

Git GUI management tool.

08. Ignore files

We can use the “ignore file” mechanism when there are permanent directories in the project, such as CSS, JS,images, etc., or directories that we do not want to commit to a remote document even if they are changed.

Ignoring files You need to create a.gitignore file. This file is used to declare rules for ignoring files or not ignoring files. The rules take effect for the current directory and its subdirectories.

Git Bash Git Bash Git Bash Git Bash Git Bash Git Bash

The common rules are as follows: 1. Filter the entire folder/MTK / 2. Filter all. Filter a specific file/MTK /do.c 4. Do not filter a specific file lindex.phpCopy the code

To create a.gitignore file:

$ touch .gitignore
Copy the code

Gitignore: for example: 1. Ignore the /js directory /js/

09.Github basic concept

What it does: Hosts project code with Github. Repository is your project. If you want to open source a project on Github, you need to create a Repository. If you have multiple open source projects, you have multiple Repositories.

2. Star refers to the number of people who collect items. Easy to check next time.

3. Clone project (Fork)

Clicking on fork while browsing someone else’s project will create a new identical warehouse in your own account, which is separate but shows forked from whose warehouse.



4. Pull a Request

This is based on Fork. After making improvements in his cloned project, Li Si wanted to merge his improved project into the original project, so he sent a Pull Request to the creator of the original project. If you are the creator of this project, you will receive this request, and you will review his code carefully, and if you think it is good, you will accept his request, and the improvements he has made will be included in your project.



Steps:

1. The fork project

2. Modify the fork project

3. Create a pull Request

4. Wait for the project creator to merge the project

5. Watch

If you follow a project, you will be notified of any future updates to that project.

6. Issue cards

When you open source a project, when others check your project and find bugs, or some things are not done well, they can Issue an Issue to you, and then you can see these problems and improve them, and then you can Close them one by one.

A Bug is found in the code, but there is no existing code, need to discuss the use of.

For example: someone submits an issue to Itcastphpgit2

Homepage Concept:

1. Making the home page

Displays user dynamics and follows user or warehouse dynamics.

2. Warehouse home page

Project information

3. Personal Homepage Personal information

Official website: Github.com

Create a Github account:





Note: The Github server is out of the country, so access is slow or unavailable.

Verify the mailbox according to the operation to create a remote repository.

Operation of remote warehouse:

1. Create a file



2. Edit the file

Click on the file name, and then click on the “small pen” pattern.

3. Upload file Click Upload File and add a description. (the Upload files)

4. Search for warehouse files click Find File

5.下载项目

点击Clone or download

10. Github Pages

Personal site access: https:// username.github. IO

Procedure 1. Create a personal site. – > Create a repository (note: the repository name must be username.github.

2. Create the index. HTML file in the repository.

Note: Github Pages only supports static web pages.

I hope I can grow up with you, make progress together, and become a better myself. I am Mengyangchen, a student in school! I hope I can be your friend. Focus on the public number [easy to play programming] reply keyword “e-book”, “computer resources”, “Java from the beginning to the advanced”, “JavaScript tutorial”, “algorithm”, “Python learning resources”, “artificial intelligence” and so on can get learning resources. The public can be the first to get relevant content oh!