Beginner Git Usage

5 min read

Git version control system usage for beginners: basic commands, workflow and best practices.

Git is one of the most important tools you will use continuously throughout your software career. Starting to use Git with just a few hours of basic training will greatly contribute to your software learning process. Take some time to sharpen your axe before entering the forest.

Start with a Visual Interface

Most IDEs have a graphical interface for Git. In this article, I will explain the basic concepts through Visual Studio Code without going into too much detail.

Use Git from Day One

No matter what project you do, start using Git from day one. Git is a local-first version control system; you can use it without connecting to a remote repository like GitHub.

At any stage of your project, you can create a Git repository by clicking the "Initialize Repository" button in the Source Control panel in Visual Studio Code. Now you can save the changes you make in the project with Git.

Basic Git Commands

Although we can use Git through the graphical interface, we can only run some commands from the terminal. That's why we need to learn CLI commands as well. Knowing the following basic commands will be sufficient:

  • git status: Displays the current status of your project
  • git add .: Stages all changes to the staging area
  • git add FILE_NAME: Stages changes of a specific file to the staging area
  • git commit -m "message": Records changes with a message
  • git revert COMMIT_HASH: Reverts a specific commit

Using Branches

Especially if you are working alone on the project, you don't need to use branches in the beginning. In the future, you will see the importance of branches in team collaborations.

Commit Habits

Make it a habit to commit after small developments. Here are things to pay attention to when committing:

  • Make small commits: Each commit should contain a single logical change
  • Write descriptive messages: Clearly state what you changed
  • Review your code: Review your code from the changes section before each commit
  • Test: Make sure your code works before committing

Advantages of small commits:

  • It becomes easier to review code changes
  • If you make a mistake, you can return to the working state by just reverting the last commit
  • Commit history becomes more understandable

Things to Pay Attention to During Development

If you see another problem while developing a feature, do not try to fix it immediately. Instead, add a //TODO comment to take notes and try to fix it later. This approach maintains your focus and keeps your commits logically separate.

Using Git While Working with AI

When developing code with AI assistance, it is important to manage changes in a controlled manner. Follow this flow:

  1. Stage your current code but do not commit
  2. Have the AI fix your code and make it work
  3. Review the unstaged changes in the Changes panel
  4. Carefully examine the changes made by the AI
  5. If the changes are appropriate, stage the new developments and commit. If not appropriate, you can revert only the changes made by the AI with "Discard Changes" - your own code stays safe in the staging area

With this approach, you can safely try AI suggestions, and easily revert changes you don't like.

Was this article helpful? You can share your comments via social media.
Other Articles