Skip to content

This happens with Git commands

Git is a version control system that makes it possible to handle changes to files. Git helps determine what has changed, who changed it and why.

A prerequisite for working efficiently with version control is knowing the most basic Git commands and the flows they give rise to.

The local computer has three different areas, working directory, staging area and local repository.

In the working directory you make all changes, such as adding new files (marked as untracked), modifying files (marked as modified) and deleting files (marked as deleted). By using git status you can get the current status of your working directory, and see whether there are changes that need to be added to the staging area.

For changes made in the working directory to be sent to the local repository, they must first be placed in the staging area, which you do with git add ., in preparation for a commit.

The local repository contains all commits (and branches). A branch, for example main, is simply a pointer to the latest commit in a chain of earlier commits.

Commit history with a branch pointer

On a server is what is called a remote repository.

Simple Git flow between working directory, staging area, local repository and remote repository

git clone downloads a repository to your computer. By default, a directory, the working directory, is created with the repository’s name, containing all files. The argument <repository> is a Git URL to a remote repository. Git automatically names the remote you cloned from origin — so it’s the connection, not the URL, that gets that name.

git add marks changes made in the working directory as staged, meaning that they are ready for a commit. With the command git status you can check whether there are changes that are staged or not.

git commit saves the changes in the staging area locally in the local repository. See Git commit best practices for how to write a good message.

git push uploads content, commits, from the local repository to the remote repository.

git pull merges changes from the remote repository into the current branch (main). See Git and multiple computers for the push/pull discipline when you work from more than one computer.

CCBY