Git basics – Initialize a new repository

Assuming that you are familiar with version control and have some basic idea about git terminology like git origin/remote etc. Here I listed some basic git commands which are frequently used while using git in the project.

Getting a repository: There can be two cases when you work on a project. If your project is not under version control than you can add your directores/files to a repository by initializing git in the project directory. Another scenario is when you start working on a project which is already under git version control and you have to download/clone the repository at your local machine.

Case 1: Initialize a new repository

Go to project directory

cd /home/Desktop/project_directory

Initialize project

git init

Add files to git

git add *.c

Commit files

git commit -m “commit message”

Case 2: clone an existing repository

Go to project directory

cd /home/Desktop/project_directory

clone from existing repository

git clone https://github.com/xxxxxxxxxxxxx.git

When you execute git clone command, this will also create a directory under your project directory. If you don’t want to create an additional directory under project directory, you can use dot at the last of git clone command as shown below.

git clone https://github.com/xxxxxxxxxxxx.git .

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to Top
Shares