10.1 Cloning a Repository
Remember I told you about the 3 places where files are stored? Remote repository, local repository, and working directory.
Now, you need to clone your remote repository (the one you created on GitHub) to your local repository (repository on your computer).
So, fire up IntelliJ IDEA and let's get started…
Step 1. If you haven't created any projects yet, select the button:
If you have, then:
Step 2. Enter the URL of your remote repository you want to clone to your computer.
This method is useful if you're cloning someone else's repository.
If you're cloning your own, it’ll be easier to log in to GitHub through IntelliJ IDEA:
Step 3. Trust no one. Not even yourself.
IntelliJ IDEA warns you not to run code from unknown repositories. Since it's your own repository, check the box trust.Step 4. The standard antivirus in Windows warns that some unknown files have appeared. Antivirus generally doesn't like programs unknown to it.
BUT! We're about to create those very programs, so ask the IDE to tell the antivirus not to block your future programs. Click on the “Automatically” button, then — “YES”.
10.2 First Commit
If you cloned a newly created repository, it will only contain one file — README.md
Step 1. Open the README.md file
The md extension stands for Markdown — a kind of rudimentary text file styling format. You can see how it works by clicking the button in the top right corner.
Change this file however you like: write any welcome message or a description of the repository.
Step 2. Once you've made changes to the file, IntelliJ IDEA will display it in blue in the file tree on the left. All changed files are shown in blue if the changes in your working directory have not yet been added to the local repository.
Step 3. Commit
After you've made all the planned changes to your file or files (and made sure they're correct), you need to upload them to your local git repository. As of now, they're only in your working folder.
For this, you need to click the Commit button and mark all the files whose changes you want to add to the local repository:
Step 4. At the bottom left, add a comment describing your changes:
Step 5. And press the “Commit” button.
Step 6. Check
Switch to your project and see: if the files have stopped glowing blue, then all changes in your working directory have been successfully added to your local repository.
10.3 Working with Files
Step 1. Let's create a few files in IntelliJ IDEA.
We're writing HTML code — let it be files:
- main.html
- index.html
Step 2. Add the file to the local repository.
As soon as IntelliJ IDEA saw that you created a file, it immediately suggested adding it to your local repository. IntelliJ IDEA tracks changes of only those files in your working directory that are already in your local repository — only those will be marked in blue.
If the file is in your working directory but not in the local repository, it's marked in red — like in the picture below:
In principle, you can always press Add, but this time let's press “Cancel” and then add the file manually so you know how to do it.
Step 3. Write your favorite code in the file.
For example, I wrote: <h1>FIRST COMMIT</h1>Step 4. Now let's add our main.html file to the local repository.
Just right-click anywhere in the file and choose Git-> Add File
If everything went well, the added file will be glowing green:
Step 5
. Then commit it the old way:10.4 First Push
Now we need to upload our changes in the local repository to the remote repository on GitHub. When several programmers work on one project, they sync their code changes this way.
Step 1. Click the Push button.
It's actually really easy to do: you just need to use the Push button in the top menu of your IDE:
Step 2. Confirm the commits.
On this step, you can review all the changes made and ensure you didn’t accidentally break something important. Or didn’t forget to add a file that other files depend on.
Step 3. Check.
If everything went well, you’ll see a message like this:
Step 4. Now open your GitHub repository and check:
The magic of technology!
10.5 Using .gitignore Files
If you've added any service files to your project and don’t want them to accidentally end up on GitHub, you can add them to exceptions. For this, there's a file named ".gitignore". It's super easy and convenient.
GO TO FULL VERSION