IntelliJ IDEA is fully integrated with Git. Learn how to initialize a local Git repository, and how to add and commit files. In addition, explore the Version Control window, where you can see files that need to be committed.
- [Instructor] Once you've install Git on your development system, you can use it to manage your projects. You can check in source code. You can maintain multiple versions, and even multiple branches. I'm going to show you here how to create a local repository, also known as a repo and I'm starting with the project CreateRepo. From the menu, I'll select VCS, Enable Version Control Integration. I'll pull down this list and show the various systems that IntelliJ IDEA can work with and I'll choose Git and click OK. That creates a new directory under your project directory.
Now you won't see it here in the Project window and that's because it's hidden. To see it, I'll go to my terminal window and then I'll type dir on Windows or ls on Mac. And once again, I won't see any special directories there. But then I'll type cd .git, lower case, and that takes me down into that hidden directory. I'll list the contents of that directory and show that there's a variety of files and folders and these are always the same for Git repositories.
So now that I know the Git repository has been created, I can add files to the repository. I'll come back to my project window. I'll right-click and scroll down to the Git submenu and I'll choose Add. To commit the files to the repository, I could go to the menu and select VCS, Git, and now that menu has changed, and then I could say Commit Directory or I could go to the Version Control tool window. I'll select View, Tool Windows, and then Version Control, which is now enabled.
I'll open up the list of available files and this lists all files that have been added to the repository but have not yet been committed. I'll click the VCS up button here. That's called the Commit Changes button and I'll see a listing of all the files that can be committed and I need to enter something called a Commit Message. I'll enter a message of Initial commit. And then under the Commit button's menu, I have options of Commit, Commit and Push, and Create Patch. Commit and Push is used when you're working with a remote repository.
I don't have that yet. And Create Patch is an advanced feature that I won't show here. I'll just Commit my changes. That actually generates yet another file called vcs.xml and I want to commit that too, so I'll click Yes, and now I only show that file in my Version Control window. I'll click the Commit Changes button again and I'll Commit. And now all of my files have been added to my Git repository. I'll go to the menu and choose VCS, Git, and then select Branches and this shows me that I have a single branch named master and that's the standard name for a brand new Git branch.
I'll talk about branches in more detail in another video. Now, let's say I want to make a change. I'll go to my Calculator class and I'm going to refactor s1 and name it string1. I just pressed Shift + F6 to do that and as I make the change, changes are being made to the underlying file on disk. And notice that the file Calculator.java is now listed again in the Version Control window. There's a change to the file and so now it can be committed again to the repository. To see what changes have been made, I'll select the file in the Version Control window and then press ctrl + d on Windows or cmd + d on Mac.
And this is the diff window. It shows me differences between the version that's in the repository that has the variable s1 and the version I'm currently working with which has the variable string1. If there are more changes than that, you can move up and down by clicking on these buttons and because I refactored that variable, I'll jump to all the changes that have been made. Now I'll commit that change. I'll click the Commit Changes button again and I'll set the Commit Message as Refactored variable name. And then once again, I'll commit.
So that's how you can easily work with a local Git repository. I'll show you some other tools working with Git in the next couple of videos.
- Exploring IntelliJ IDEA editions
- Installing IntelliJ IDEA on macOS and Windows
- Configuring IntelliJ IDEA
- Creating new projects
- Importing an Eclipse project
- Exploring the user interface
- Editing and debugging code
- Building, compiling, and packaging Java projects
- Managing multiple branches with Git
- Programming with Groovy, Scala, and Kotlin