Skip to content

Welcome to GitFlic


So, you decided to use git, but don’t know where to start? You can use this documentation as a desktop reference and consult it for many common questions. To get started, you should create your project. Once you’ve created your new repository, you need to set up your local workspace. Use the console on your PC to work.

For Windows users, we recommend installing a dedicated console for working with git. Just search for "Git for Windows", choose your preferred solution, and install it.

Creating a Local Directory

Create a local folder for your future repository by running the following commands in your console:

cd ~/
mkdir repos
cd ~/repos

Global Git Settings

Set your user information with the following commands:

git config --global user.name "gitflic-user"
git config --global user.email "mail@gitflic.ru"

Next, choose the option that suits your situation and execute the commands in order:

Create a New Repository

git clone http://gitflic.ru/project/user/proekt.git //This is the link to your project
cd proekt
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

Use an Existing Directory

cd existing_folder
git init
git remote add origin http://gitflic.ru/project/user/proekt.git //This is the link to your project
git add .
git commit -m "Initial commit"
git push -u origin master

Push an Existing Repository

cd existing_folder
git remote rename origin old-origin
git remote add origin http://gitflic.ru/project/user/proekt.git //This is the link to your project
git push -u origin --all
git push -u origin --tags

After executing these commands, you will see that your local/remote directory is filled with files. Now that you’ve set up your repository, it’s time to learn how to use branches in git.

Create a Branch in git

To create a new branch and immediately switch to it, use the following command (where omega is the name of the new branch):

git checkout -b omega

You can also perform these actions in two steps — create the branch first and then switch to it:

git branch omega
git checkout omega

Common Options for git branch

Display a list of branches in the local repository:

git branch

Display all branches in both the local and remote repositories:

git branch -a

Delete branch omega. This is a “safe” operation because git won’t allow you to delete a branch with unmerged changes. This command deletes only the local branch:

git branch -d omega

Force-delete branch omega, even if it contains unmerged changes. Use this command if you want to completely delete all commits related to a particular development direction:

git branch -D omega
git push origin :refs/heads/omega

For visualizing files under git control, there’s the TortoiseGit extension. It has an intuitive interface and displays icons for files under git control to show their status.

Generating a Public SSH Key

Many servers use SSH key authentication for working with git. Here’s how to create your SSH key for git. The process is the same on all operating systems. First, make sure you don’t already have an SSH key on your local computer by running:

cd ~/.ssh
ls

Look for files named id_dsa or id_rsa and the corresponding file with a .pub extension. The .pub file is your public key, and the other file is your private key. If these files (or the .ssh directory) are missing, you can create them using:

ssh-keygen -t ed25519 -C "your_email@example.com"

Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/gitflic_user/.ssh/id_ed25519):
Created directory '/home/gitflic_user/.ssh'.
Enter passphrase (empty for no passphrase): (leave blank, press Enter)
Enter same passphrase again:
Your identification has been saved in /home/gitflic_user/.ssh/id_ed25519.
Your public key has been saved in /home/gitflic_user/.ssh/id_ed25519.pub.
The key fingerprint is:
d0:82:24:8e:d7:f1:bb:xx:yy:zz:96:93:49:da:9b:e3 gitflic_user@gitflic.ru

After creating your public SSH key, you need to add it in the settings under SSH keys. First, get your SSH key from the file. You can open your public SSH key in a text editor and copy its contents, or run:

cat ~/.ssh/id_ed25519.pub

After copying your SSH key, add it in settings, specify a name for the key, such as my-ssh, and leave the expiration date field blank so your SSH key remains active indefinitely. After clicking Add, your public key will appear in the list Your SSH keys.

Common Commands When Working with git

git clone

The git clone command creates a copy of the specified repository in a separate directory. The original repository may be on the local filesystem or on a remote device accessible via supported protocols.

Example of cloning a project into the current directory via HTTPS:

git clone https://gitflic.ru/project/user/project.git

Example of cloning a project into the current directory via SSH key:

git clone git@gitflic.ru:user/project.git

git add

The git add command adds changes from the working directory to the staging area. It tells git that you want to include updates to a particular file in the next commit. However, this command doesn’t actually affect the repository in any significant way—the changes are not actually recorded until you run git commit.

Add all changes to the next commit:

git add .

To add only one modified file to the next commit, use git add file-name, where file-name is the full file name:

git add file-name

You may also find git status useful for viewing the state of your working directory and staging area:

git status

git commit

To commit the indexed state of your code, use git commit:

git commit

This will open a text editor to add a commit message. After entering your comment, save the file and close the editor to complete the commit.

To commit all changes in the working directory, use git commit -a. This includes changes to already tracked files (which were previously added with git add):

git commit -a

The git commit -m command creates a commit with the specified comment. By default, git commit opens a local text editor for you to enter a commit message. With the -m parameter, the specified comment is used, bypassing the editor:

git commit -m "commit message"

There is also a parameter that allows the git commit command to amend the last commit. Instead of creating a new one, all changes are added to the last commit. After running the command, the text editor will open and let you change the previous commit message:

git commit --amend

git pull

To download and merge remote content into the local repository, use git pull. This is essentially equivalent to running git fetch <remote> to get the contents from the specified remote and then git merge origin/current-branch to merge the remote contents into a new local commit:

git pull <remote>

The option git pull --no-commit merges the contents but does not create a new commit for the merged content:

git pull --no-commit <remote>

git push

The git push command publishes the specified branch to a remote repository, along with all necessary commits and internal objects. This creates a local branch in the destination repository. To prevent commit overwriting, git won’t allow you to push if a fast-forward merge cannot be performed in the destination repository:

git push <remote> <branch>

If you specify origin for <remote> and leave branch empty, the changes will be pushed to the currently selected branch.

The -u parameter (same as --set-upstream) sets the “default” remote branch; all subsequent git pull/push commands will automatically communicate between the current local and selected remote branch. This command is used only once, until you need to set another default remote branch:

git push -u origin master

There is a procedure for cleaning up local and remote branches that helps keep things tidy and prevents the accumulation of changes that won’t be loaded into the main project branch. The first command deletes the local branch alpha. If you put a colon before the branch name in the git push command, it will delete the remote branch:

git branch -D alpha
git push origin :alpha

git log

The git log command displays the commit history in the repository, starting from the most recent commit. Commits are shown in chronological order, with the newest commit at the top:

git log

The command git log <path> will show the commit history for the specified file. Note: it only shows commits that make actual changes to the specified file. If a file’s changes were reverted in later commits, those commits won’t appear. This is because the command analyzes changes relative to the current file state.

git log <path>

Commits that don’t affect the final result are skipped. More details can be found in the section Differences in commit history display.

The git log --oneline command displays a brief description of each commit in a single line. This can be useful when you want a general overview of commits without extra details:

git log --oneline

With git log --graph, you can view the commit history as a graph. This makes it easy to visualize branches and merges and see how commits relate to each other:

git log --graph

To display the complete graph of changes and find commits that may have been reverted, use:

git log --all --decorate --oneline --graph

The command git log --author=<name> will display only commits made by the specified author. This is useful if you want to review commit history for a specific project participant:

git log --author=<name>

The git log --since=<date> command displays commits made after the specified date. This is useful if you want to study commits made after a certain event or release.

git log --since=<date>

This is just a small set of git log arguments. You can also use various options, such as output formatting, limiting the number of displayed commits, and more.

You can learn more about git log using the built-in help:

git help log

Automated translation!

This page was translated using automatic translation tools. The text may contain inaccuracies.