Git

Git Clone Version Example

As we know, Git has been widely used among software programmers. It is free and open-source. Also, it’s powerful by its distributed nature, fast operation and branch handling mechanism. The distributed property makes it easy and efficient for multiple developers to work together, towards the same project. In addition, Git works fast with its lightweight operations. Lastly, every developer can work with the code as its own branch. Others can merge different branches, which makes cooperation-work quite easy.
 
 
 
 
 

1. Introduction

Github is a web-based Git repository. It is also called remote repository, compared to the local repository. Firstly, it provides web-based GUI and desktop GUI, as well as mobile integration. Also, it provides access control and other features for collaboration. Because of these, it is very useful for bug tracking, task management for every project.

For Git and Github, they do have close connections with each other. And we can use different commands to make them connect. For more command options, go to my previous Git tutorial. Before that, you may also need to install Git and set up Github. For instructions on this, you may refer to my previous article Git clone repository example.

In this article, we will focus on a very important Git command: git clone. This command will clone/download a repository from Github.

All the examples below is shown in MacOS EI Capitan Version 10.11.5 and the Git version is 2.7.4.

2. Git clone version example

2.1 git clone command

In Git, git clone is a very important command. You can understand it as cloning/downloading a repository into a new directory from a remote server, like Github. Hence, we can use this command to connect to Github, based on knowing the project git link.

To make it clear how it works, I’ll show you with an example. For instance, you may interest in the Datastax Java driver for the NoSQL database Apache Cassandra. You can go to the Github link https://github.com/datastax/java-driver. Below this figure shows how it looks for our project.

java driver
Datastax Java driver

Then, if you need to download it and work on this project on your local machine. You can use git clone command. To make it work, you need to figure out the git link for this project. For this project, the git link is https://github.com/datastax/java-driver.git. The position of this link which you can copy is below with the blue part marked.

git link
Git link

Then, open the terminal on your computer and go to the directory that you want to save this project. Type git clone https://github.com/datastax/java-driver.git. Then, it’ll download this project to your local machine like below:

WXMs-MacBook-Pro:~ WXM$ git clone https://github.com/datastax/java-driver.git
Cloning into 'java-driver'...
remote: Counting objects: 50300, done.
remote: Total 50300 (delta 0), reused 0 (delta 0), pack-reused 50299
Receiving objects: 100% (50300/50300), 20.78 MiB | 266.00 KiB/s, done.
Resolving deltas: 100% (21551/21551), done.
Checking connectivity... done.

Then, you can go to the directory of the project. Furthermore, you can check the status with command git status. It works like below:

WXMs-MacBook-Pro:~ WXM$ cd java-driver/
WXMs-MacBook-Pro:java-driver WXM$ git status
HEAD detached at origin/3.0
nothing to commit, working directory clean

The status shows that the current HEAD is at remote repository origin on branch 3.0.

2.2 git clone version

Normally, when we work on a project, we may have multiple versions. These versions may have different functions to work on. Git also support for multiple versions. And it makes version-control very convenient. So we still take the Datastax Java driver as an example.

In our previous command, when we clone with the git link, we clone all branches. With the usage of command git branch -a, you can get the list of all branches in this project. Similarly, you can see our example below:

git branches list
git branches list

In the figure above, you may find out different numbers like 1.0, 2. 0, 3.0 etc. Actually these are the branches for this project. You can also click the branches like below to see the detailed information of different branches.

git branches figure
git branches figure

From the figure above, we can see that current branch is 3.0. Also, if you’re careful enough, you may find there’s a tags tag belong with the branch tag. You can click the branch tag and find the tags tag. You can check it like below:

git tags
Git tags

Here, under the Tags tag, you can find the version number like 3.0.0, 3.0.1 and 3.0.2. Normally, the version comes from 1.0 to up, like 2.0, 3.0. And these changes normally are big changes. Then some other version name changes like 3.0.1 to 3.0.2 is just small bugs improvement or modification.

So normally, the branch is kind of like a big branch with different versions. For example, in branch 3.0, it has version of 3.0.1, 3.0.2 and 3.0.3 etc. With these branches and version tags, it’s very convenient for us to manage the whole project. You can check the whole version number with git tag command:

WXMs-MacBook-Pro:java-driver WXM$ git tag
1.0.0
1.0.0-beta1
1.0.0-beta2
1.0.0-rc1
1.0.1
1.0.1-dse
1.0.2
1.0.2-dse
1.0.2-dse2
1.0.3
1.0.3-dse
1.0.4
1.0.4-dse
1.0.5
1.0.5-dse
1.0.6
1.0.6-dse
1.0.7
1.0.8
2.0.0
2.0.0-beta1
2.0.0-beta2
2.0.0-rc1
2.0.0-rc2
2.0.0-rc3
2.0.1
2.0.10
2.0.10.1
2.0.11
2.0.12
2.0.12.1
2.0.12.2
2.0.2
2.0.3
2.0.4
2.0.5
2.0.6
2.0.7
2.0.8
2.0.9
2.0.9.1
2.0.9.2
2.1.0
2.1.0-beta1
2.1.0-rc1
2.1.1
2.1.10
2.1.10.1
2.1.10.2
2.1.2
2.1.3
2.1.4
2.1.5
2.1.6
2.1.7
2.1.7.1
2.1.8
2.1.9
2.2.0-rc1
2.2.0-rc2
2.2.0-rc3
3.0.0
3.0.0-alpha1
3.0.0-alpha2
3.0.0-alpha3
3.0.0-alpha4
3.0.0-alpha5
3.0.0-beta1
3.0.0-rc1
3.0.1
3.0.2
cassandra-driver-parent-2.0.9

Furthermore, if you want to go to specific branch with specific version, you may use the following command with git checkout with the version number. For example, we might want to go to the version of 3.0.0-rc1. Then with the following command, we can accomplish this:

WXMs-MacBook-Pro:java-driver WXM$ git checkout 3.0.0-rc1
Previous HEAD position was 8fc9511... Update contribution guidelines
HEAD is now at d858301... [maven-release-plugin] prepare release 3.0.0-rc1

This means that we’re under the repository of version 3.0.0-rc1. Right now you see how easy it could be to manipulate the versions and branches.

3. Conclusion

With the default version-control property, Git makes it very easy to work on different versions and branches. Hence, this makes convenient for us to manage our project. With the command git checkout, we can switch between different version and branches. So, let’s start and work on our own project with different versions:)

Jun Wu

Jun (Steven) Wu is a current Master student in Computer Science & Engineering department of University of Nebraska Lincoln (Lincoln, NE, USA). His current interests focus on Programming Languages (Java, Python), Relational Database (MySQL), NoSQL Database (Apache Cassandra, MongoDB), and Computer Networks.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button