Introduction
First and foremost, you need to understand the concept of Git. What it is, its purpose, and how it functions. Without delving into technical details. For instance, the Fundamental Concepts | NUS Hackers Wiki or What is Git? Our beginner’s guide to version control | The GitHub Blog articles appear intriguing.
Feel free to find another one if you’d like:
Initialization
If you’re starting with a directory that doesn’t have Git initialized, run the command to initialize Git:
git initAfter that step, when running:
git status…you’ll find successful information similar to this:
On branch main
No commits yet
nothing to commit (create/copy files and use "git add" to track)Cloning
Another starting point is cloning a Git repository. Of course, such a repository should already exist and be created by someone.
Cloning is an operation that downloads the repository to your local machine from a remote server. You can perform this operation by running the command git clone <repository-url>. For example, to clone my repository https://github.com/kniziol/dotfiles from GitHub, you would use the following command:
git clone git@github.com:kniziol/dotfiles.gitAn example of successful output:
Cloning into 'dotfiles'...
remote: Enumerating objects: 256, done.
remote: Counting objects: 100% (112/112), done.
remote: Compressing objects: 100% (86/86), done.
remote: Total 256 (delta 56), reused 56 (delta 26), pack-reused 144 (from 2)
Receiving objects: 100% (256/256), 447.06 KiB | 1.20 MiB/s, done.
Resolving deltas: 100% (131/131), done.Now, you can visit the dotfiles directory and view its contents, which are identical to those found at https://github.com/kniziol/dotfiles on GitHub:
ls -alh dotfilesStatus
To view the current state of your local repository, including modified files and branch name, run the following command:
git statusLogs
To view commits and the history of changes made, run the git log command:
git logor one of its variations that provides more detailed information:
git log --statgit log --onelineCreate a new branch
To create a new branch run the git branch <new-branch-name> command:
git branch feature/test1However, a faster method is to create a new branch and switch to it by running the git checkout -b <new-branch-name> command:
git checkout -b feature/test1Make a change and create a Commit
Create an empty text file:
touch first-text-file.txtNow edit that file in your favorite text editor, and add some text to it:
vim first-text-file.txtVerify current status:
git statusAn example of successful output:
On branch feature/test1
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
first-text-file.txt
nothing added to commit but untracked files present (use "git add" to track)The newly created file, first-text-file.txt, is shown in the „Untracked files” section. Therefore, let’s add the file to the staging area:
git add first-text-file.txtSee the current status:
On branch feature/test1
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: first-text-file.txtYou’re now ready to create a commit that includes all the changes you’ve made and staged. Let’s create a commit:
git commit -m "Create a first text file"Oops, you need to specify commits author:
Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.Let’s set the author’s name and email address, specifically for this repository:
git config user.email "kn@localhost"git config user.name "Krzysztof Nizioł"Let’s create a commit now:
git commit -m "Create a first text file"[feature/test1 02167bd] Create a first text file
1 file changed, 2 insertions(+)
create mode 100644 first-text-file.txtYou can easily where your commit is by running the git log command:
git logAn example of successful output:
commit 02167bd3f0cf1e926e83c0362874994c777159f6 (HEAD -> feature/test1)
Author: Krzysztof Nizioł <kn@localhost>
Date: Sat Dec 27 18:29:41 2025 +0100
Create a first text fileMerge branches
Let’s consider a scenario where you’ve completed all the necessary changes and want to share them with others. In such a case, we need to merge our branch into the main branch, which is the common, root branch. To do that, use the git merge <branch> command.
First, let’s switch to the main branch:
git switch mainNext, merge the feature/test1 branch into the main branch:
git merge feature/test1Other commands
git pull: updates your current local working branch with all new commits from the corresponding remote branchgit push: uploads all local branch commits to the remote branchgit remote -v: displays the associated remote repositories and their stored name
Useful resources
Here are some other interesting sources of information about Git:
- GitHub Git Cheat Sheet
- The Pro Git book by Scott Chacon and Ben Straub