GIT commonly used basic operations, from building a library to branching

I have been using the TortoiseGit tool to carry out the daily operations of git. Today I am going to take Git completely and take aside.

First talk about the difference between Git and GitHub. Git is a warehouse for storing code documents, and GitHub is a service that provides Git repositories on the Internet. GitHub is the front-end implementation we have seen, and Git manages it later. Separate the two, or there will inevitably be troubles behind.

Then we first need to create our own account on www.github.com. After the creation is complete, you will receive a verification code email for the mailbox used for registration. This step is very simple.

Then create a new library for yourself, for
GIT commonly used basic operations, from building a library to branching
example, I fill in the designModel in the small red box below, so that an empty library is built.
GIT commonly used basic operations, from building a library to branching
From the bottom, you can operate directly on the local git

Then the first step is to install Git. I installed Git-2.25.1-64-bit. This is the default installation all the way.

After the installation is complete, execute the creation of the .ssh directory and the generation of the public key / private key in the BIN directory of the GIT installation.
Use the CMD window to jump to the BIN directory of the GIT, execute sh.exe to
GIT commonly used basic operations, from building a library to branching
perform the directory creation operation mkdir ~ / .ssh ( It should be noted here that it is already in the style of bash, do not use the window command under windows)
GIT commonly used basic operations, from building a library to branching
After completion, a .ssh directory will be generated in the user directory of the C drive

Create a public / private key and execute the ssh-keygen -t rsa -C "Account @ Mailbox" command (the account here is the mailbox when registering a github user), the account marked in the black box in the figure below (even @include the mailbox 1 behind And enter)

Note that the ssh-keygen in front is connected together, do not disconnect

After the execution is completed, two corresponding files id_rsa and id_rsa.pub will be generated in the local .ssh directory.
Then paste the contents of id_rsa.pub (in the public key file). After posting the corresponding public key information in the ssh configuration area under the setting menu of GitHub
GIT commonly used basic operations, from building a library to branching
, you will receive another email in your mailbox normally, with the following information written
If you believe this key was added in error, you can remove the key and disable
access at the following location:

That's ok

After completion, you can connect to github normally.

Then the first thing to do is to get the empty library we created on github to the local first. Here you have to choose the location where you want to put the library. For example, I want to put the library in the workspace-git directory of the d drive. Just run GitBash in this directory,
GIT commonly used basic operations, from building a library to branching
so after entering the bash running window, the directories it operates are based on the current directory, and then you can execute the git clone command
git clone https://github.com/mas199980/DesignModel .git is followed by the connection of my own library,
this is connected to the github page to find, you can also use the git remote -v command to find
GIT commonly used basic operations, from building a library to branching

After successful execution, a relevant directory is generated locally, and subsequent operations of uploading and downloading code are executed in this directory

After the clone is successful, there will be a folder containing the .git file with the same name as the library. Then I created an initial maven project with eclipse in this file, and then I need to push the newly created file to the library. The steps I need are as follows:

1. Execute the git add command to add the corresponding files to the cache area. If you write. It is all the files in the current directory
GIT commonly used basic operations, from building a library to branching
2. After you finish, submit the files to the local management, execute git commit, I have a parameter for this commiit A note-m (because there is no screenshot of the previous operation, I will add one here, so the note is to add the readme.md file)
GIT commonly used basic operations, from building a library to branching

3. Finally, we push the local commit to git and execute git push
GIT commonly used basic operations, from building a library to branching

When prompted to cancel this push success, you can see the code you submitted to on the github website.

Such a basic forward process is completed. We can often check whether there is no commit operation locally through the git status command, and it will be enough to submit the incomplete commit.

Below is another very common operation of git, which is to branch. When the team develops an online system, it often encounters bugs and needs flying together. The bug is bound to hit the release branch immediately, but the demand may only be developed to half. In this way, there must be at least two branches, one for continuing to make requirements, and the other branch to patch to release, and then before the next round of release, all patches must also be merged into the main branch of development.

You can see what branches are currently under git through the git branch command. In my case, there are now two branches, one is the master and the other is the feature-A branch that was just used for branch testing. I am currently operating the master branch by default (this must be noted that the on-site version confusion often means that the developer mentioned the wrong branch when submitting the code version, resulting in various tragedies -_-)
GIT commonly used basic operations, from building a library to branching

Let's create a new branch below, git checkout -b feature-A, this is the command to create the feature-A branch that I just saw. After the execution is successful, the new branch is created. At the same time, the current working branch will also be switched to the new branch by default (the command to switch back to the original branch is git checkout master)
GIT commonly used basic operations, from building a library to branching

After the switch is complete, you can operate on this branch. Just as on the main branch, commit operations include add, commit, and push (when pushing, pay attention to the branch name on git push origin feature-A). After completion, you can also see the corresponding modification on github

Then the changes on feature-A will eventually be merged into the master. This will be done as follows:
first
switch back to the main branch (that is, the branch to be merged), and then execute the merge command git merge --no- ff feature-A
GIT commonly used basic operations, from building a library to branching

In this way, the changes on feature-A are merged into the main branch. But at this time, there is no change on github, and you need to perform another git push operation.

Finally, execute the git status command to see the latest merger. The red line is the master branch, and the green line is the newly-featured-A branch.
GIT commonly used basic operations, from building a library to branching

In this way, the most basic git operation command is completed. Students who are generally used can basically carry out daily operations.

If you encounter a version conflict situation and cannot simply cover the code to solve the problem, this is a taboo for development. Be sure to check the conflicting parts of the code in detail before proceeding. It can be solved by the above routines, or you can check the commands for merge resolution, and the commands for revoking the version.

Guess you like

Origin blog.51cto.com/4890631/2486355