JavaRush /Java Blog /Random EN /IDEA, Git, BitBucket in practice. Part 1: Basics. We work...
Sdu
Level 17

IDEA, Git, BitBucket in practice. Part 1: Basics. We work locally.

Published in the Random EN group
Tired of carrying a flash drive with JavaRushHomeWork.7z from work to home and from home to work, once again forgetting to copy unfinished tasks, I made a strong-willed decision not to wait for level 39 and set up a Git + BitBucket combination for personal use. BitBucket , because there are free private repositories (don’t forget about the JavaRush rules), and Git , because Git, because it was well-known, because I was already asked about it. At that moment, everything seemed simple and clear: register on bitbucket.org , install Git , press one magic button and my files appear on the server, press another and miraculously continue working with the current files in another place. I read it here and here , registered, installed, registered, connected, clicked "Share project", entered a name, selected a type and... a miracle did not happen. It didn’t take off, the server was empty... With regret I was forced to state a couple of facts: you can’t do without a tambourine, I don’t understand at all what was supposed to happen in reality, so to speak, under the hood, and what do all these new words mean that appeared in my life in an instant. So, be patient, pick up the wonderful Pro Git book and start all over again.

Just a little bit of theory to warm up.

Version control is a system that tracks changes to one or more files and allows certain older versions to be restored. Git is a distributed file version control system. A distributed version control system is a system in which the entire history of changes is stored on each computer, in local storage, and, if necessary, individual fragments of the history of the local storage are synchronized with a similar storage on another computer. What does this mean for us? And the fact is that on any computer involved in the process, we will locally have a copy of the repository we need. In fact, the main work is done with the local repository . Therefore, at this stage we forget about BitBucket and learn to work with Git in IDEA locally.

Installing Git.

You can get the distribution on the project website git-scm.com There is no point in describing the installation procedure in detail, the installation is trivial, and the settings available at this stage are quite clear. In addition, the Internet is full of installation materials, including videos. Attention should be focused on only one point: if you install Git after IDEA, in the latter you must specify the path to git.exe. If IDEA was installed after Git, the path will be added automatically. IDEA, Git, BitBucket in practice.  Part 1: Basics.  We work locally.  - 1

Creating a Git repository.

There are two ways to create a git repository:
  1. Import an existing project or directory into Git.
  2. Clone an existing repository from the server.
We will consider the second point later, when we move on to working with the Git server, but for now we will focus on the first point. Initially, Git is designed to work from the console, in command mode, therefore, for a better understanding of what is happening, below I will give Git commands and illustrate them with menu commands or keyboard shortcuts in IDEA. At the same time, you can work on the command line directly from IDEA. IDEA, Git, BitBucket in practice.  Part 1: Basics.  We work locally.  - 2 Input: A simple IDEA project with one class file. IDEA, Git, BitBucket in practice.  Part 1: Basics.  We work locally.  - 3 To create a repository, use the command git initThis command will create a new .git subdirectory in the current directory with the necessary files, the basis of the Git repository. Similarly, in IDEA - VCS - Enable Version Control Integration IDEA, Git, BitBucket in practice.  Part 1: Basics.  We work locally.  - 4 IDEA, Git, BitBucket in practice.  Part 1: Basics.  We work locally.  - 5 IDEA will cheerfully report on the successful completion of the operation, a couple of new tabs will appear in the "Tool Buttons", and in the "Version Control" tab we can see the executed commands and their results. IDEA, Git, BitBucket in practice.  Part 1: Basics.  We work locally.  - 5 IDEA, Git, BitBucket in practice.  Part 1: Basics.  We work locally.  - 7

Adding files

We have created the basis of the repository, but the project is not yet under version control. And here we should make a small lyrical digression. In Git, files can be in one of three states: committed, modified, and prepared. Committed means saved in the repository. Changed - files that have been changed but not committed. Prepared - modified files marked for "commit".
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION