1. 程式人生 > >How to clone a GitHub project to go work space > LinxLabs

How to clone a GitHub project to go work space > LinxLabs

In this post I’ll explain how you can clone a project from git hub to your go work space
If you don’t have a project on GitHub to play with ; then please read this post to create one

So lets start

Go to GitHub project page to copy git URL

Try to clone the repository using ‘go get’ with the URL we copied

[email protected]:~> go get https://github.com/OpenLinXlabs/Golang-Tutor.git
package https:/github.com/OpenLinXlabs/Golang-Tutor.git: "https://" not allowed in import path
[email protected]:>;

It failed with message indicating that we cannot use “https:..” while mentioning URL

Now lets try without “https://”

[email protected]:~> go get github.com/OpenLinXlabs/Golang-Tutor.git
package github.com/OpenLinXlabs/Golang-Tutor.git: invalid version control suffix in github.com/ path
[email protected]:~>

Failed again saying invalid version control suffix – which means we cannot use .git suffix in URL

Now lets try again without .git suffix

[email protected]:~> go get github.com/OpenLinXlabs/Golang-Tutor
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/OpenLinXlabs/Golang-Tutor: exec: "git": executable file not found in $PATH
[email protected]:~>

Failed again with messaging saying , we need “git” binary

Install git package

Go to root and install ‘git’ package using one of the procedure below based on your distro.

For Fedora Based distros like RedHat or CentOS

# dnf install git-all

For Debian based distros like Ubuntu

# apt-get install git-all

Now lets try to execute go get again

[email protected]~>; go get github.com/OpenLinXlabs/Golang-Tutor
# github.com/OpenLinXlabs/Golang-Tutor
github.com/OpenLinXlabs/Golang-Tutor/hello.go:5:14: invalid character literal (more than one character)
github.com/OpenLinXlabs/Golang-Tutor/hello.go:5:14: cannot use '\u0000' (type rune) as type string in argument to fmt.Printf
[email protected]:~>

Failed once again with messages indicating syntax errors in our source .go file

Correct the syntax errors as mentioned by editing the file from GitHub

Now execute go get again

[email protected]:~&amp;gt; go get github.com/OpenLinXlabs/Golang-Tutor</pre>
[email protected]:~> ls -lR $GOPATH/src
/home/linxlabs/go_workspace/src:
total 1836
drwxr-xr-x 3 linxlabs users 4096 Oct 14 01:55 github.com

/home/linxlabs/go_workspace/src/github.com:
total 4
drwxr-xr-x 3 linxlabs users 4096 Oct 14 01:55 OpenLinXlabs

/home/linxlabs/go_workspace/src/github.com/OpenLinXlabs:
total 4
drwxr-xr-x 3 linxlabs users 4096 Oct 14 01:56 Golang-Tutor

/home/linxlabs/go_workspace/src/github.com/OpenLinXlabs/Golang-Tutor:
total 44
-rw-r--r-- 1 linxlabs users 72 Oct 14 01:56 hello.go
-rw-r--r-- 1 linxlabs users 35141 Oct 14 01:56 LICENSE
-rw-r--r-- 1 linxlabs users 52 Oct 14 01:56 README.md
[email protected]:~>

voila.! it worked.

Now you can see the project directories and files

In my next post I’ll explain basics of git and how to push changes from command line to your github repository