In the work, GitLab/GitHub is a necessary tool, this article records a basic Git interaction process, easy to use in the workplace small white Settings.

Environment configuration

First you need to install git, get the installation package directly next can be successfully installed.

The git download

Once installed, right-click anywhere to find git’s command line window:

Account configuration

Think back to any collaborative development projects you’ve worked on. Does every file/folder have a recent record? In fact, every change to this file is recorded by Git precisely from the moment it is born. So how does Git distinguish the people who make changes? It is through our pre-configured account, which records your name and contact information (email). If someone needs to change this file, they can contact you in time.

Git also has two ways to set username and email:

Git config --global user.name "testName" git config --global user.email "[email protected]" Git config user.name "testName" git config user.email "[email protected]"Copy the code

It’s usually a separate setting in the company, as it’s separate from your personal GitHub.

Git Settings must be in the same directory as the **.git** folder.

This folder is hidden and needs to be opened in Settings:

To view the configuration, run the following command:

git config user.name
Copy the code

SSH configuration

Once you have your name and contact information, there’s another problem to solve: pass-through.

When you submit your code, you will have to log in. Every time you submit your code, you will need to enter your username and password again, which is really tedious.

Imagine if anyone with a name could submit code, the company's projects would be a mess.

SSH is an asymmetric encryption technology, unlike HTTP, which can automatically authenticate as long as you configure the public and private keys.

1. Generate a key pair

First we need to generate a key pair, enter the following command, press Enter.

Too many students did not enter, causing them to think that the generation error...

Once generated, you can see the pair of files in your user path /.ssh, which is a public key and a private key.

2. Configure the public key on GitHub

Once you’ve generated the key pair, you need to tell GitHub to stop pestering you for login authentication in the future.

Title is a custom Title

Key is the ** public Key (id_rsa.pub) **

Code to pull

1.git clone ssh-path

Once the environment is configured, the first step is to clone the company code. Since we have configured SSH, we can simply paste its path:

2. Switch branches

After clone is removed, the default branch is master branch, which needs to be switched (generally the company will develop in dev), and the command is as follows:

Git checkout -b specifies the name of the origin branch and the name of the remote branch. Git checkout -b specifies the name of the origin branch and the name of the remote branchCopy the code

Local Warehouse submission

Once you’ve made changes to your code, commit your changes to Git for other colleagues to see.

1.git add .

Add the modified/newly added files to your local repository for Git management.

2.git commit -m “”

View the modified file and commit it selectively. Since some parts of the file do not need to commit even if they are modified, and some commit logs are written, it is recommended that this step be done in the IDE:

Select only the files to be submitted.

Push the code

The final step is to push the local branch to the remote repository:

Git push --set-upstream origin/ upstream originCopy the code

The branch name here should be the same as the one you specified when you checked out -b, and it will be created automatically for you if it doesn’t exist at the remote end.

Multi-person collaborative flow

Here is a summary of Mr. Liao Xuefeng:

Git learning

Personally, the common submission process is:

1. Merge git pull with remote code to resolve conflicts

2. Git commit Commit the change code

3. Git push to remote branch

Making added

If you are using GitHub to manage your project, you may need to manage a project from scratch. After creating a new repository, you will be led to a boot page:

Follow the prompts to deploy your project into the repository.