How to Clone from Git Repository using go into current directory

Posted on

The main focus of this article is how to clone a package or folder from Git repository. The clone process is possible with the help of ‘go’ command. The result of the clone process is available in the current directory where the execution of the command exist.

In order to achieve it, there are several steps to accomplish the purpose. Below are those steps :

1. First of all, the obvious step is to check the availability of the ‘go’ command. Type the ‘go’ command in the command line. If the ‘go’ command is not exist just try to install it first. Read the article for installing ‘go’ in this link or in this link.

2. Next step, after checking that the ‘go’ command is available. Check the location of the ‘go’ command. Just type the following command to find out the path of the ‘go’ command :

user@hostname:~$ which go

3. So, normally by default, every package or directory as the result of the cloning process using the ‘go’ command exists in the ‘/usr/bin’ path. The problem will appear when a specific user executes the command but that user doesn’t have the write permission in the ‘/usr/bin’ path. It will generate an error message similar with the one available in the article in this link.

4. Eventually, in order to solve the problem, it is already exist in the article in this link. But there is one adjustment to the solution. The path as the value of the environment variable is the key of the adjustment. Change it to the following line :

export GOPATH=${PWD}

Actually, rather than using ‘/home/user/go’ value as the path, just define it into ‘${PWD}’. It is a value for representing the current working directory or folder. As a result, every clone command of a package or directory, the output or the cloning result will exist in the path where the execution command takes place.

5. Don’t forget to execute the following command to apply the change of the environment variable in the above file :

user@hostname:~$ source .bashrc

6. Finally, execute the following command to check the value of the ‘GOPATH’ environment variable just to make sure :

user@hostname:~$ echo $GOPATH

Leave a Reply