Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.

Git Versioning System

eu42 edited this page Feb 16, 2016 · 2 revisions

Git Versioning System

What is Git?

Git is a distributed version control system (VCS) which is widely used among developers. In general, VCS enables user to track history of the files and to create different versions for the files. User can switch between these versions. In a distributed VCS, each user has a clone of the repository on her computer usually among with a repository running on a server.

GitHub is one of the most popular site which uses Git, yet GitHub offers not just Git.

In this text, Git will be explained with some of its useful commands. For further information, refer to References section. This text is written according to Ubuntu, for other operating systems there might be differences with commands and their usages.

Installation

For installing Git use:

sudo apt-get install git

Initializing a Repository

For creating a repository from scratch:

git init <directory>

It creates a new Git repository at .

Cloning a Repository

For this project, we will not create a new Git repository but instead clone the existing repository from GitHub. For cloning a Git repository:

git clone <repository>

It will clone the repository to current working directory. As an example, you can clone this project using:

git clone https://github.com/bounswe/bounswe2016group2.git

Configurations

You can configure your Git installation with git config. There are many things you can do with this command, as an example you can set your user name and email adress globally with:

git config --global user.name <name>

git config --global user.email <email>

Adding a new file

git add <file> will add to Git repository for your next commit. git add <directory> will add to Git repository for your next commit.

Making a commit

git commit will make a commit after prompting a text editor for commit message.

Alternatively, git commit -m "<message>" will make a commit with .

Pull and Push

Here, we need to make a little explanation. When you make a commit, the changes you made with that commit will be stored locally. That means after a commit, others cannot see the changes you made. For that to happen, you need to 'push' your commits to the server.

If main repository hasn't been changed since your last 'pull' command, you can directly push your commits. If there has been any changes, you will need to pull those changes first. It will check your local files and if there are local changes, it will try to merge local version and new version automatically. If merge cannot be made automatically, you will need to do it manually. After merging, you can push your commits to the server.

For pulling changes from the server,

git pull

For pushing your commits to the server,

git push

Current status

You can see the current status, which changes have been staged etc using

git status

Branches in Git

In Git, you can create branches. Until now, we think always on a single collection of files, make all changes on this collection. With branching, you can create a new 'branch' or simply duplicate the collection and make different commits and changes on different branches. At some point, you can also merge branches. For further information, you can refer to References.

git branch list all branches.

git branch <name> will create a new branch named as

git checkout <branch> will let you navigate between branches.

git merge <branch> will merge with current branch.

References

Clone this wiki locally