Working with Git — Part 1

Bhupendra Joshi
3 min readMar 4, 2017

--

Part 2, Part 3, Final

Repository

Like with most version control systems the first thing you do is, either create a repository or get an existing repository.

Create a repository

Create a Git repository locally by executing ‘git init’ command OR via GUI OR you can create Git repository on server like (GitHub, BitBucket, GitLab, etc) and clone it locally.

Get an existing repository

Using command line go to the directory you wish to clone the repository type:

git clone <git repo url.git>

Using GitExtensions click on Clone Repository and then use your Git repository URL of the server and clone it locally.

How to differentiate what is local and what is server’s?

Most Git GUIs will show the branch name on the commit, when there is no prefix to the branch like ‘origin/’ you know that it is your local repository. The prefix is to show an external path. These are called as remote paths and can be updated in remote repositories section. When you clone an existing repository or do your first push of a new repository, the tracking between local and server repository is established. By default the server repository is denoted by ‘origin’ however it can be changed to whatever you like.

In the above image ‘master’ is local and ‘origin/master’ is remote (server).

Branching

One of the most important part of having a version control system is doing your changes in isolation. Making sure it works and passes integration and only then getting it in to a release of a product. For this, version control systems provide a mechanism which is called branching, via which you get a branch. A branch is is a copy of a section of your repository i.e. copy of commits.

In Git you are always working on a branch whether it is main (master) branch or feature branch. In Git you create a branch from another branch, the source is then called as parent branch.

A Git repository starts with a ‘master’ branch. When you start development you do not directly make changes on your master branch, that branch is suppose to be stable always, pointing to latest released. Instead you create a branch from your stable branch and you make your changes there.

You create a branch by right clicking on the parent and then say create branch. If for any reason you have started working on your source branch, but while committing you realize that you should have created a new branch then it is OK, you can create a branch with your current uncommitted changes.

--

--

Bhupendra Joshi

Reader, follower, thinker, designer, developer — just lazy in all levels