Clone Process in Git and Local Repository Operations

If you are new to Git we suggest you to have a quick look on below posts before starting with Git Clone process:

Distributed Version Control System: Git

Git Installation for Windows and Linux

Setting Up Central/Remote Git Repository in Bitbucket


Central to local Repository Cloning –

We have a central repository available at Bitbucket accessed by any user/team (who have valid access) who can copy (or in terms of Git we call it “clone”) a repository to their local systems and perform related tasks. Once done they can merge the changes and release them to be used in the products/product features. In this post we will learn how to clone repositories locally and perform tasks on local repositories.

Git

1.) We might be having multiple repositories in Bitbucket (for different projects), its always a best idea to create a “repo” directory inside which we can clone our central available repositories. We will use “Linux Based OS” and will create a directory called “/home/thinknyx/repo” inside which we will clone our “thinknyxdemo” repository which we have created in the last post.

[root@thinknyx~]#pwd
/home/thinknyx

[root@thinknyx~]#mkdir repo

[root@thinknyx~]#cd repo

[root@thinknyx~]#pwd
/home/thinknyx/repo

2.) Go to your Bitbucket account, click repository which you want to clone and copy the link provided on the screen (or click I’m starting from scratch). It will ask for the password of bitbucket account as we have created a private repository in our previous post.

[root@thinknyx~]#git clone https://[email protected]/thinknyxtechnologies/thinknyxdemo.git
Cloning into ‘thinknyxdemo’…
Password for ‘https://[email protected]’:
warning: You appear to have cloned an empty repository.
[root@thinknyx~]#

[root@thinknyx~]#pwd
/home/thinknyx/repo

[root@thinknyx~]#ls -lrt
total 0
drwxr-xr-x 3 root root 18 May 15 01:50 thinknyxdemo

[root@thinknyx~]#ls -lrt thinknyxdemo
total 0

Working with Local Cloned Repository –

Now we have a copy (clone) of the central repository locally in our system, we are free to perform any development as we are working with local repository now. Lets create few files and directories locally and later on push them in central repository to reflect changes centrally.

1.) Go to the clone repository locally and create some demo files.

[root@thinknyx~]#echo “This is a demo on Git by Thinknyx Technologies” >> demofile
[root@thinknyx~]#echo “This is a second file on GIT demo by Thinknyx Technologies” >> demotwofile

2.) git status – Run git status to check any untracked files (i.e files which are written in cloned repository locally). Sometimes this space where we have done the changes is called “working directory Area”.

[root@thinknyx~]#git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use “git add <file>…” to include in what will be committed)
#
#       demofile
#       demotwofile
nothing added to commit but untracked files present (use “git add” to track)
[root@thinknyx~]#

3.) git add – Next step is to run git add command which moves changes from the “working directory area” to the “Git staging area”. The staging area is where you prepare a snapshot of a set of changes before committing them to the official history. If there are no error in the add command nothing will be returned.

[root@thinknyx~]#git add demofile

[root@thinknyx~]#git add demotwofile

[root@thinknyx~]#git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use “git rm –cached <file>…” to unstage)
#
#       new file:   demofile
#       new file:   demotwofile
#

4.) git commit – Next, we have to commit the changes, The git commit takes the staged snapshot and commits it to the project history. Combined with git add, this process defines the basic workflow for all Git users. In Command “-m” stands for comments or message while performing commits.

[root@thinknyx~]#git commit -m ‘Demo Commits by Thinknyx Technologies’
[master (root-commit) c06e9fc] Demo Commits by Thinknyx Technologies
2 files changed, 2 insertions(+)
create mode 100644 demofile
create mode 100644 demotwofile

[root@thinknyx~]#git status
# On branch master
nothing to commit, working directory clean
[root@thinknyx~]#

We have three major areas when we work with Git locally:

  • “working directory Area” – A place where we do changes locally in git repository
  • “Staging Area” – while using git add
  • “Commit history” – while using git commit

Till this point we haven’t performed any changes in the central repository at Bitbucket, all of the operation have been performed locally.

In our next post we will push the locally repository changes centrally and will perform other Git operation from Bitbucket and local server.

Leave a Comment

Your email address will not be published.