Git has a lot of the client tools, but feel or command line operations had better use, convenient and quick, but command line operations need friends for Git command is more skilled, it may have some difficult for some people, so the client tools cannot abandon, sometimes if you recommend a Git client tool, I think it’s Git plug-in in IDEA. Other Git client tools songko have also experienced some before, but feel that IDEA is more convenient to use.
Today’s article is the second time I teach you to use Git in development tools. When I just graduated, Songge wrote an article to teach you to use Git in Eclipse. At that time, using Git in Eclipse was really troublesome, even plug-ins had to be installed for a long time. That was seven years ago.
Seven years later, Eclipse has lost its glory, and IDEA has gradually become the mainstream tool for development. Let’s take a look at using Git in IDEA today.
1. Basic configuration
First you need to install Git, this does not need me to say more, IDEA is also installed by default Git plug-in, you can directly use.
GitHub is used as a remote repository. If you don’t know the difference between GitHub and Git, you can check the Git tutorial in the menu bar at the bottom of jiangnan Dianyu, an official account.
Starting from 2021.08.13, there is a small change in GitHub configuration on IDEA, that is, the user name and password cannot be used to log in to GitHub. If you try to log in to GitHub using the user name and password to submit code, you will receive the following prompt:
Support for password authentication was removed on August 13, 2021.
Please use a personal access token instead.
Copy the code
The following error occurs when you log in to GitHub using the user name/password on IDEA:
We need to click on the Use Token in the upper right corner to log in to GitHub using a Token. The Token generation method is as follows:
- Log into your GitHub account on the web.
- Click on the upper right corner and select Settings:
- Drag to the bottom and select Developer Settings on the left:
- Select Personal Access Tokens on the left and click Generate New Tokens on the upper right:
- Fill in the basic information and select the repo and GIST permissions.
- Finally, a token is generated and copied to IDEA as follows:
This is the basic configuration.
GitHub is usually not used as a remote repository for developers in the company, so you can configure it according to your actual situation.
2. clone
On the first day at work, the Clone project should be completed first. There are clone tools in IDEA, which we can use directly:
You can also select the GitHub directly below and pull the new code directly from your GitHub repository.
After clone is completed, IDEA will prompt you whether to open the project. Select Yes.
Once the code is cloned, you are ready to start developing Git Flow as described earlier by Songo.
Branch 3.
Create develop and Release Branches as follows: Select the current project, right click on it, and select Git->Repository->Branches… :
Or click on VCS->Git->Branches at the top… :
Of course, both methods are troublesome. Directly clicking the lower right corner of IDEA is the most convenient and most commonly used method, as shown in the picture below:
Select New Branch and create a New Branch. Check “Checkout” to switch to the Branch.
Select a branch and click Checkout to switch to that branch:
Next we commit the Develop branch to the remote repository as follows:
We haven’t changed the code, so just click the Push button to submit.
The submission was completed successfully. The origin prefix of Develop and the Remote Branches of The Develop branch have been appended.
Now suppose we want to pull a branch called feature-login from Develop to do the login as follows:
From the created log, we can see that feature-login does come from develop:
Well, now we can start the day off happily
After the feature development on feature-login is completed, click the upper right corner of IDEA first to complete the submission of the local warehouse, as shown below:
Click on the bottom right corner to complete the code submission. Note that this is only a submission to the local repository.
Since we will not commit feature-login to the remote repository, we will merge feature-login into Develop and push the latest Develop to the remote repository as follows:
- Switch back to the Develop branch.
- Select feature-login->Merge into Current to Merge.
If you want to delete the feature-login branch after the merge is complete, you can also delete the branch in the IDEA log:
The develop pointer points to feature-login, and you may need to add the –no-ff parameter to the merge.
Switch from feature-login back to the Develop branch and look like this:
Take a look at the commit log as follows:
As you can see from this log, this is no longer fast merge mode!
Finally, select Develop ->Push to commit the code to the remote repository.
4. pull
In IDEA, if you need to update the code from the remote warehouse, click the button in the upper right corner, as shown below:
Ok, so that’s the general process.
Of course Git is extensive and profound, IDEA supports many functions, other functions need to be explored by friends, if you don’t understand welcome comment discussion.