Creating and cloning repositories on Git and GitHub

Zainab Daodu
4 min readJan 27, 2023

--

Introduction to Git & GitHub

Git is the world’s most popular distributed version control system. It’s open-source, free, and can handle small to big projects. Git makes it simple to build new project repositories on your local disk or clone existing repositories.

GitHub is a web-based platform that hosts software development projects using the Git version management system. It is a central repository where developers can collaborate to exchange, review, and work on code.

One of GitHub’s core features is the ability to build and manage repositories, which are collections of files tied to a certain project. Each repository has many branches, which are various project versions you can contribute separately.

Prerequisites

  • Install Git on your computer or download the latest version of Git from the official website at https://git-scm.com/.
  • A text editor such as Sublime Text or Visual Studio Code.
  • A terminal like PowerShell or command prompt.
  • Internet connection: Git is a distributed version control system, which means you can work with a repository locally without an internet connection. However, you need an internet connection to clone a repository from a remote server or to push changes to a remote repository.

Creating a repository on Git

To create a repository on Git, follow these steps:

  1. Open the file manager and navigate to the directory where you want to create your repository.
  2. Left-click and click “Git Bash Here.
  3. In the terminal, run the following command to initialise a new Git repository:
git init

For more details, check out our previous article on creating a repository.

Cloning a repository

Cloning a repository means creating a local copy of a remote repository on your computer. This is useful when you want to contribute to a repository and need a local copy to which you can edit and commit changes.

Cloning a repository from GitHub to your local machine

To clone a repository, use the git clone command in your terminal or command prompt, followed by the URL of the repository you want to clone. For example,

git clone <repo URL>

Creates a new directory and downloads the content of the remote repository into the directory. The local copy of the repository can be set up to track the remote repository to pull and push changes between them easily.

Updating a local clone with changes from the remote repository

To update a local clone of a repository with changes from the remote repository, use the git fetch and git merge commands. Here is the basic workflow:

  1. Open a terminal or command prompt and navigate to the directory containing your local clone of the repository.
  2. Run the following command to retrieve the latest changes from the remote repository:
git fetch

This downloads the changes but does not apply them to your local clone.

3. To see the changes that have been fetched, use the git diff command to compare your local clone with the remote repository. For example,

git diff HEAD origin/master

This merges the differences between your local master branch and the master branch on the remote repository.

4. To apply the changes to your local clone, merge them using the git merge command. For example,

git merge origin/master

This is the change from the origin/master branch (which represents the remote repository) into your local master branch.

5. To push your updated local clone back to the remote repository, use the git push command. For example,

git push

This pushes your local changes to the remote repository, updating it with the changes you have made.

Hurray, you have successfully created and cloned repositories on Git and GitHub!

Conclusion

This post covers instructions on creating and cloning repositories on Git and GitHub. If you find this article useful, don’t forget to hit the "Clap" button or leave a comment if you have any questions. Also, feel free to ask questions or contribute to our conversations on Twitter.

--

--

Zainab Daodu

Zainab is a technical writer with years of experience in writing technical documentation and articles to improve developer experience.