CodeGym /Courses /Kotlin SELF /Developer’s daily workflow: Commit, Push, and .gitignore

Developer’s daily workflow: Commit, Push, and .gitignore

Kotlin SELF
Level 18, Lesson 1
Available

1. Getting started: cloning a project

Let’s start from where we left off in the previous lecture. You have a repository created on GitHub, and now you need to get its local copy on your computer to begin working. This process is called cloning.

Step 1. Launch your IDE. If you have any project open, close it via File | Close Project. On the start window (Welcome Screen), choose Clone Repository (or Get from VCS).

Step 2. In the window that opens, paste the URL of your repository. This approach is useful if you are cloning someone else’s repository. You can copy the URL from the repository page on GitHub.

Entering a URL for cloning

If you are cloning your own repository (our case), the easiest way is to sign in to your GitHub account directly from the IDE. To do that, choose the Log in to GitHub option. Your IDE will open a browser for authorization.

JetBrains IDE authorization window on GitHub

On the page that opens, confidently click the green Authorize JetBrains button. After that, you’ll be able to select your repositories directly from the list in the IDE. Choose the required project and click Clone.

List of repositories for cloning

Step 3. Your IDE will ask whether you trust this project. Since this is your own repository, click Trust Project.

Step 4. Antivirus setup (for Windows users)

Windows antivirus may warn you that the IDE is trying to perform actions it doesn’t recognize. Since we are going to create and run programs, we need to allow the IDE to work without restrictions. Click the “Automatically” button so the IDE adds the required folders to the antivirus exclusions on its own.

Configuring antivirus exclusions

2. Saving changes: Commit

commit is a “snapshot”, or a saved state of your project at a specific point in time. Think of it as a save point in a game: you can always return to it if something goes wrong. Each commit has a unique identifier and a message describing the changes made.

        gitGraph
        commit id: "Initial commit"
        commit id: "Add user authentication"
        commit id: "Fix login button bug"
        commit id: "Refactor database connection"
    
Commit history. Each new commit is built on the previous one, creating a chronology of the project’s evolution.

Step 1. Make changes.

If you cloned a newly created repository, it will contain only one file — README.md (and hidden IDE folders).

Open the README.md file and add a description of your project. As soon as you start editing the file, the IDE will highlight its name in blue in the Project panel. This means the file has been changed, but the changes have not been saved to Git yet. The IDE will add a green line where you made changes.

Highlighting a modified file

Step 2. Open the Commit window.

On the left side of the IDE there is a Commit tab. Opening it, you will see all changes ready to be saved. This is your Staging Area.

Commit window in IntelliJ IDEA

Let’s break down what we see:

  • Changes: these are files that are already tracked in Git but have been modified. In our case, it’s README.md, where we added the project plan.
  • Unversioned Files: these are new files that Git sees in the project folder but does not track yet.

Important

Before you press the Commit button, always check with your own eyes which files have checkmarks next to them. This is especially important for the first commit.

If you see the Unversioned Files list contains the .idea/ folder (and especially the workspace.xml file, which changes with every mouse click) or the build/ folder — stop! These service files must not end up in the shared history. The good news: if you created the repository with a .gitignore template, Git will hide these folders automatically. If they are visible, you urgently need to add them to ignore (we’ll cover that at the end of the lecture).

For now, our goal for the first commit is to check the main project files and write a clear message in the Commit Message field.

Step 3. Make a commit.

Click the blue Commit button. Done! You’ve saved a “snapshot” of your project in the local repository. The file name will return to its normal color.

Successful commit

3. Sending changes to GitHub: Push

Your commits are still stored only on your computer. To share them with the team or keep them in a reliable place, you need to send them to the remote GitHub repository.

        sequenceDiagram
        participant Local repository (your computer)
        participant Remote repository (GitHub)

        note over Local repository (your computer): You made one or more commits.
They exist only here. Local repository (your computer) ->> Remote repository (GitHub): git push (send commits) note over Remote repository (GitHub): Your commits are copied
and safely stored on the server.
Your local commits are sent to the remote server, syncing the project history.

Step 1. Click the Push button.

In the interface, the Push button is located on the main top toolbar (Main Toolbar). It looks like an arrow pointing up and to the right. Click it.

Push button on the Main Toolbar

Step 2. Review and confirm.

A window will open where you will see all commits that are ready to be sent. This is your last chance to make sure you are sending exactly what you need. Click Push.

Push confirmation window

If everything went well, you will see an IDE popup notification: Pushed commits to origin/main. Create pull request.

Step 3. Check the result on GitHub.

After a successful push, open your repository page on GitHub in a browser. You will see that your changes and files appeared there.

4. Git control panel

Your IDE has a dedicated Git tool window, as well as quick actions on the top Main Toolbar. This is your version-control command center. Let’s get familiar with the key buttons.

Git controls in the IDE
  • Commit (checkmark): opens the panel for saving changes.
  • Push (arrow up/right): opens the window for sending your commits to GitHub.
  • Branches: opens the widget for branch management (in the top-left corner).
  • Show Git Log: shows the full commit history of your project on the Git tab. Your personal time machine.

The morning starts with Update Project

The Update Project button performs a critical function — it downloads the latest changes from other team members from the GitHub server to your computer (runs git pull).

Make it a habit: every morning, before writing even a single line of new code, click this button. If you start working with outdated code while your colleagues have already changed the same files, by lunchtime you’ll end up with a difficult merge conflict.

5. Using .gitignore files

If service files or compilation outputs appear in your project and you don’t want them to accidentally end up in the repository, you need to add them to exclusions. For this, a special file named .gitignore is created in the project root.

Kotlin specifics and why we ignore folders

In the Kotlin world, the de facto standard build system is Gradle, and the main development environment is IntelliJ IDEA. They generate many service files that are strictly forbidden to push to Git:

  • build/ — this is where the compilation results of your code are stored (.class files, .jar archives). They weigh tens to hundreds of megabytes, and the build tool regenerates them on each developer’s computer. Keeping them in Git means quickly running out of server space.
  • .gradle/ — local cache of the build system.
  • .idea/ — local IDE window settings (which files you have open, font size, paths to local SDKs). Your teammates don’t need your personal UI settings, and the workspace.xml file changes literally every second.

How to add a file to ignore manually:

Step 1. Suppose you created a temporary file notes.txt with passwords for a test database. Right-click it in the Project tool window.

Creating a temporary file

Step 2. Go to the Git menu -> Add to .gitignore -> Add to .gitignore. This option adds the selected file to the .gitignore file in the root of your project.

Adding to .gitignore via the menu

If you don’t have a .gitignore file yet, the IDE will offer to create it. Agree.

Step 3. Your IDE will automatically add the file name to .gitignore.

File added to .gitignore

After that, ignored files will be displayed in the project tree in gray or olive. When you try to commit, Git simply “won’t see” these files. The main thing is — don’t forget to commit the .gitignore file itself, so all members of your team download these ignore rules.

What if I already committed it?

.gitignore ignores only new, not-yet-tracked files. If you accidentally already committed the build/ folder, it is in the history, and Git will keep tracking it even if you add it to .gitignore. In such cases, you’ll need to clear the cache (for example, with git rm -r --cached build/ in the terminal), but it’s better to simply prevent junk from getting into the first commit.

Rules for .gitignore

The .gitignore file specifies patterns of file and folder names that Git should ignore. Empty lines are ignored. To add a comment, start the line with the # character.

  • * — matches any number of any characters. For example, *.log ignores all files with the .log extension.
  • / — at the end of a pattern means a directory. For example, build/ ignores all contents of the build folder.
  • ! — at the beginning of a line inverts the rule. For example, if you have a rule *.log but you want to track important.log, add the line !important.log.
  • ** — matches any number of nested folders.

Example .gitignore file for Kotlin and Gradle


# Gradle compilation and build outputs
build/
.gradle/
out/

# Local IDE files and settings
.idea/
*.iml
*.iws

# Operating system files
.DS_Store
Thumbs.db

# Logs
*.log

Ready-made templates

You don’t have to write these files from scratch. There are ready-made, community-verified templates:

  1. GitHub’s .gitignore collection for different languages and frameworks: https://github.com/github/gitignore.
  2. gitignore.io — a handy web service that generates a .gitignore file for your stack (just enter Kotlin, Gradle, IntelliJ).
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION