Another article related to Git function or utility which in this context it is a versioning control. The versioning control in this article is focused on how to clone a Git repository via command line by using an example on how to do it. So, in other words, duplicating or copying a repository which exist locally or remotely can be done by executing the following command provided by Git utility. In this article, the process itself is done by typing the command in a CLI (Command Line Interface) such as terminal, etc.
At first, before the actual duplicate or copy process can be done, there are several prerequisite which is needed :
1. Install Git utility
2. Check whether the ‘git’ command can be executed. Below is an output example showing the execution of git command :
user@hostname:~$ git usage: git [--version] [--help] [-C ] [-c name=value] [--exec-path[=]] [--html-path] [--man-path] [--info-path] [-p | --paginate | --no-pager] [--no-replace-objects] [--bare] [--git-dir=] [--work-tree=] [--namespace=][] These are common Git commands used in various situations: start a working area (see also: git help tutorial) clone Clone a repository into a new directory init Create an empty Git repository or reinitialize an existing one work on the current change (see also: git help everyday) add Add file contents to the index mv Move or rename a file, a directory, or a symlink reset Reset current HEAD to the specified state rm Remove files from the working tree and from the index examine the history and state (see also: git help revisions) bisect Use binary search to find the commit that introduced a bug grep Print lines matching a pattern log Show commit logs show Show various types of objects status Show the working tree status grow, mark and tweak your common history branch List, create, or delete branches checkout Switch branches or restore working tree files commit Record changes to the repository diff Show changes between commits, commit and working tree, etc merge Join two or more development histories together rebase Forward-port local commits to the updated upstream head tag Create, list, delete or verify a tag object signed with GPG collaborate (see also: git help workflows) fetch Download objects and refs from another repository pull Fetch from and integrate with another repository or a local branch push Update remote refs along with associated objects 'git help -a' and 'git help -g' list available subcommands and some concept guides. See 'git help ' or 'git help ' to read about a specific subcommand or concept. user@hostname:~$
3. Perform the actual command to duplicate or to clone the repository. The command pattern is shown below :
git clone repository_address Description : git : the command used to call the git utility clone : the parameter command used to duplicate or to clone the repository where it is located in the value specified after repository_address : the repository address given to be cloned or duplicated. In this context of article, there are two type of addresses, it is using 'SSH' or 'HTTP' protocol.
For an example :
user@hostname:~$ git clone http://myapp.repository.com/gitlab/myuser/myapp.git Cloning into 'myapp'... Username for 'http://myapp.repository.com': myuser Password for 'http://[email protected]': remote: Counting objects: 9385, done. remote: Compressing objects: 100% (6643/6643), done. remote: Total 9385 (delta 2319), reused 9291 (delta 2236) Receiving objects: 100% (9385/9385), 24.68 MiB | 11.05 MiB/s, done. Resolving deltas: 100% (2319/2319), done. Checking connectivity... done. user@hostname:~$
So, at the end, there will be a folder named myapp in the home folder of user, precisely at ‘/home/user/myapp’. It is the result of executing the above command.
One thought on “How to Clone a Git Repository via Command Line with an Example”