Working with GIT – Part 1 (Creating my first git project)

I have started working on git recently for my projects and find it a huge step towards keeping my work organized and synced. I learned a lot from around the web and decided to give the information back to the web in a way as concise as possible. Below we layout the steps for creating git project.

What is git?

In a nutshell, git is a source code management system.

If helps teams (or an individual) to work on the same code, irrespective of their work location. It saves all the changes in versions, so if someone needs to access to a certain code after it has been rewritten several times, he would be able to do so easily. To collaborate with the team (or with yourself only), git is a great tool and should be integrated to your routine.

Getting Started

Task: Download GIT and install

Windows: http://git-scm.com/download/win Download will start automatically

For OSX, visit https://code.google.com/archive/p/git-osx-installer/downloads

For linux, visit https://git-scm.com/book/en/v2/Getting-Started-Installing-Git

Task: Getting a git server to host the code

Either you can manually host a server to host the git for you and do all the work yourself, or use one of the existing services who have done all the boiler-plate code already. If you prefer to do all the work yourselves, good luck on your endeavor.

If you prefer the second approach to use one of the existing services, then you can choose from one of the many service providers for git. A quick search can lead to tens of results, the most popular ones being github, gitlab, bitbucket, etc.

I prefer to use github and gitlab as they both serve different purposes for me.

Github is very popular and is the best way to showcase your open source projects. A free account at github allows only public repositories, whereas in gitlab, you can host both public and private repositories for free. For the rest of the post, I will refer to gitlab as the repository host.

First head over to gitlab and register your account there. It’s registration process is very simple and requires only your name, an username, your email and the password, and you can get started from there.

gitlab-login-register

After you register and login, you will presented with a simple and intuitive dashboard.

Task: Creating a new git project

gitlab-dashboard
gitlab-new-project

In your dashboard, you will see a ‘+’ button. Click on that, and you will be guided to a new page to create a new project.

When you create a new project, it will look something like the above screen.

Give your project a name – I have given test-project-1. You can also give an optional description

There are also a lot of importing options for your projects at other locations like Github, BitBucket, etc.

The next block will allow you to set the ‘Visibility Level’ for your project (Private, Internal & Public). The best thing about gitlab is that it allows to host Private projects in the free tier account too. Set the ‘Visibility Level’ and hit the ‘Create Project’ button and your project would be created.

Note down the link for your newly created project, which would be something like https://gitlab.com/{your-username}/{your-project-name}.git

Task: Create a new repository

Create a new directory in your work area.

Open the git terminal and navigate to the newly created directory, and type

git init

This will instantiate the repository to behave as a git repository. To verify, you can see a .git folder inside the directory. As .git is a hidden folder, so you need to have the “View Hidden Files and Folders” to true to see it.

Task: Start working

In your terminal, type

git remote add origin https://gitlab.com/{your-username}/{your-project-name}.git

This will set your working directory git project url to the project you created at gitlab

Now you can start adding files to your project.

Task: Pushing changes to git server

In your terminal, type

git add .
git commit -m "message"
git push origin master

This will push all your changes to the git server.

Task: Pulling changes from git server

In your terminal, type

git pull

This simple command will fetch all the changes from the server and be available for edits.

Task: Cloning a repository

By cloning a repository, you can get a local copy of the source code and files and start making changes to it. This can be done by

git clone {path-to-repository}

Murari Mohan Nayak (Murari M.)

Leave a Reply

Your email address will not be published.