I heard that wechat search “Java fish” will change strong!

This article is in Java Server, which contains my complete series of Java articles, can be read for study or interview

What is Git used for

If you’re working in an Internet company, you’re likely to hear about version control. Version control is the practice of keeping a history of changes to files, code, etc., during development so that you can view, back up, and roll back historical code.

At the same time, it can be used to manage multi-person collaborative development projects, realize multi-person parallel development through version control, and improve development efficiency.

Git is an implementation of version control, as is Svn, etc.

Git is also known as distributed version control. All version repositories are synchronized to every user’s local location, and can be submitted offline locally, and pushed to the corresponding server when there is a network.

(2) The use of Git

Git bash and Git GUI are displayed after installation on a Windows PC. You are advised to use Git bash. After the MAC is installed, run the git command directly on the terminal.

2.1 Configuration Information

View all configuration information
git config --list
Check the system configuration
git config --system --list
Check the global configuration
git config --global --list
Copy the code

2.2 Setting the User Name and Email Address

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

The first two steps are part of configuring Git after you install it

2.3 Initializing the Local Git Repository

If you want to turn a local folder into a Git repository, just do it

git init
Copy the code

2.4 Cloning a Remote Repository

If you want to download the remote repository code locally, you just need to execute it in a directory

git clone [url]
git clone -b [branchname] [url]
Copy the code

-b is used to clone the code of the specified branch

2.5 Three steps to submit documents

Add the file to the staging area
git add filename
Commit files in the staging area to local
git commit -m "Submit information"
git push
Copy the code

We can also pull and commit the code directly, which is more convenient.

3. The working principle of Git

There are four important areas in Git:

Working Directory: Where the project code is normally stored

Stage: Temporary storage of changes

Repsitory/Git Directory: Data for all versions committed

Remote Directory: a platform for code hosting

Working directory –>git add Files –> staging area –>git commit–> Repository –> Git push–> remote repository

Git ignores file uploads

Create a. Gitignore file in your home directory and you can skip committing certain files

*.txt # ignore all.txt files! a.txtExcept the # a.t xt
temp/ # ignore files in temp
Copy the code

(5) SSH secret free login

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

After three consecutive press enters, id_rsa and id_rsa.pub will be generated in the. SSH directory. The string in id_rsa.pub will be saved to the SSH public key in gitee Settings to submit the download code without encryption

(6) Branch management

Branching is the core of distributed versioning. Branches are not related to each other, and a new branch is basically created for each iteration of the release.

# list all branches
git branch

List all remote branches
git branch -r

Create a new branch, but remain in the current branch
git branch [branch-name]

Create a new branch and switch to that branch
git checkout -b [branch]

Merge the specified branch into the current branch
git merge [branch]

# delete branch
git branch -d [branch-name]

# delete remote branch
git push origin --delete [branch-name]
git branch -dr [remote/branch]
Copy the code

(7) Integration of Git and Idea

Idea itself supports Git integration. When we clone a project to the local, we will find the Git logo in the upper right corner after opening it with Idea:

The first blue arrow represents pulling the remote repository code locally.

The second green check box represents the commit code. Check the code to commit and push, fill in the commit information, and then commit and push.

The third alarm clock is the submission history, which allows you to view historical submission information.

(8) Summary

For work, you only need to be able to submit pull code using Idea. But we need to understand how Git works. I’m fish boy. See you next time!