How to clone a GitHub repository?

GitGitHubOpen SourceSoftware & Coding

Cloning a repository involves downloading a copy of the source code from source control. In other words, cloning is creating a copy of an existing repository. Consider an example where multiple users are working on a project. This feature can be used by the users to create a development copy.

If you have a GitHub repository, you need to first invite collaborators into the repository. Each collaborator will then clone the repository into their local machines.

Locally they will work with this cloned repository, make local changes and perform commits on it. Once they are ready to share their changes with others in the team, they will push the commits to the central repository.

In order to clone a repository, we need to follow the steps given below −

Copy the URL from the text box shown above and paste this into your git bash terminal using the below command.

$ git clone {repo_rul}

This will create a folder in your machine with the same name as that of the project.

$ dell@DESKTOP-N961NR5 MINGW64 /e/tut_repo
$ git clone https://github.com/kannan/sample.git
Cloning into 'sample'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.

$ dell@DESKTOP-N961NR5 MINGW64 /e/tut_repo
$ ls
sample/

Change the current working directory to the project folder and execute the git log command as shown below

$ dell@DESKTOP-N961NR5 MINGW64 /e/tut_repo
$ cd sample/

$ dell@DESKTOP-N961NR5 MINGW64 /e/tut_repo/sample (main)
$ git log --oneline --all --graph
* b494547 (HEAD -> main, origin/main, origin/HEAD) Initial commit

In the above output, origin is the name given by git for the remote tracking branch (i.e., the source branch that was cloned). origin/main and origin/HEAD are remote tracking branches. In order to view the details of the remote tracking branch use the following command

$ git remote -v
origin https://github.com/kannan/sample.git (fetch)
origin https://github.com/kannan/sample.git (push)

-v means verbose so this will list the details of the remote tracking branches.

raja
Published on 28-Apr-2021 14:29:19
Advertisements