Basic Git Operations

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git is also easy to learn and has a tiny footprint with lightning fast performance.

(See also Basic SVN Operations)

Git Advantages:

  • Better support to paralell development
  • Possible to make changes and not to affect other users work
  • Doesn’t require network
  • Branch is effective and does not “torture” users
  • Faster than SVN
  • Faster access to logs and revisions because everything is on a local machine

Git Concepts:

  • History of changes for all users
  • Complete data of the repository
  • Doesn’t require to user has an active Internet connection
  • Working Tree: Every user has his own work directory

Basic Git Operations:

Note: Repository must be initialized

git init

Execute in a directory which we’ll use for versioning.

Inside that directory will be created subdirectory .git which contains all informations about repository.

git --bare init

Makes folder under GIT control on server

git remote add origin <repository_url>

Adds main shared repository.

git status

Checks files state. (unregistered files, changes in files, adding files)

git add <file>

Adds a single file to versioning.

git add .

Adds all files from directory into versioning.

git commit -m "Comment for commit"

Before commit, files must be added  to the stage.

Commit is a point in GIT repository history which contains set of one or group of files.

It is necessary to add a comment with commit.

git commit -a -m "Comment for commit"

Avoiding stage.

git log

View GIT log.

git rm <file>

Removes specified file.

git rm --cached <file>

Removes tracking but keeps file in directory.

git mv <file> <new_filename>

Rename file with new_filename.

git reset HEAD <file>

Removing file from stage.

File stays changed but doesn’t participate in commit.

git checkout -- <file>

Discarding changes in file.

File is returning to version in commit before.


Working with others

git clone <repository_path>

Gets remote repository.

git pull

Gets all changes from remote repository.

git push

Sends all commits to remote repository.

git mergetool

Starts tool for merging in conflicts.


Branching Operations

Branches are used for parallel development in more independent streams of the same repositories.

git checkout <branch_name>

Creates new branch with specified name and if branch exists, goes to that branch.

git checkout main

Returns to main directory.


Git Usage Example

Here is an example how to use GIT:

git clone <repository_url>
git add <untracked_file>
git add <changed_file>
git commit –m "..."
git pull
git mergetool
git commit
git push

For more informations visit official Git website:

Leave a Reply

Your email address will not be published.