Creating a Local Git repository in ubuntu

Agenda :
1) Create a remote repository in local file system
2) Create a workspace
3) Create a empty repository
4) Add Initial file
5) Add remote origin
6) Push the code to remote repo
7) Creation of new branch
8) Pushing the new branch
9) Viewing all branches and Changing branch
10) Merging development branch to Master branch

 
1) Creation of a local repository
———————————————————–
We need to define a location where the git repository will reside.
For this, we will create a local git repo.
To start with the local git repositary setup, first, we have to create a local directory.
I chose the below location for this.

cd /;
sudo mkdir gitrepo;
sudo chmod 777 gitrepo;
cd gitrepo;
mkdir project_1;
cd project_1;
git init –bare;

2) Creation of workspace
———————————————————–
To start working, you need a workspace. I chose the below location as workspace

cd ~/;
mkdir workspace;
cd workspace;
mkdir project_1;
cd project_1;

4) Creation of Empty Depositary
———————————————————–
Initiate a empty repositary here.

git init;

4) Adding Initial files.
———————————————————–
Add your required initial files to the repo.

echo “This repository is to learn creation of local git repos” >>README
git add README;
git commit -m”Initial Commit”

5) Adding Remote origin
———————————————————–
Now, we have to specify, where we will store this repository.
Remember?? We have created a local repository at first?
Else, check 1 Creation of a local repository

Now, we are going to use this location as the remote location.

git remote add origin /gitrepo/project_1

6) Pushing the code to remote repo
———————————————————–
Now, we can push the code to the remote repo we have added.

git push origin master

The end master indicates, we need to push to the branch called as master in the remote repo.

To test the setup so far.. i.e. to check whether our code is safe at remote repo, lets try the below.

cd ../
rm -rf project_1;

git clone /gitrepo/project_1;
cd project_1;
ls;

Now, we should be able to see out previously added file.

7) Creation of new branch
———————————————————–
Now, we will create a branch for development..

In the workspace repo, we will create a local branch at first. Then we will push this branch to the remote repo.

git checkout -b devel

git status, should tell that you are in the new branch devel

8) Pushing the new branch to remote :
———————————————————–
Once you have added your development code, to push the new branch to the remote repo, follow the below..

git add *;
git commit -m”Adding development code”
git push origin devel

This would push the branch to the remote repo..

9) Viewing all branches and Changing branch
———————————————————–
To list all of branches in current repo, run

git branch -a

A start will be present to indicate the active branch.
Remote branches will be preceded with remotes/origin/ in their path.

To change to a particular path, run

git checkout -b branch_name

10) Merging development branch to Master branch
———————————————————–

git checkout master
git pull
git merge devel

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s