This tutorial provides an overview of how to set up a repository (repo) under Git version control. This resource will walk you through initializing a Git repository for a new or existing project. Included below are workflow examples of repositories both created locally and cloned from remote repositories. This guide assumes a basic familiarity with a command-line interface.
What is the Github Repository?
A repository is like a folder for your project. Your project’s repository contains all of your project’s files and stores each file’s revision history. You can also discuss and manage your project’s work within the repository. You can own repositories individually, or you can share ownership of repositories with other people in an organization.
Create a new Github Repository.
- In the upper-right corner of any page, use the drop-down menu, and select New repository.
- Type a short, memorable name for your repository. For example, "hello-world".
- Optionally, add a description of your repository. For example, "My first repository on GitHub."
- Choose to make the repository either public or private. Public repositories are visible to the public, while private repositories are only accessible to you, and people you share them with. For more information, see "Setting repository visibility."
- Select Initialize this repository with a README.
- Click Create repository.
Congratulations! You’ve successfully created your first repository and initialized it with a README file.
Create Github repo using the command line.
- Open Git Bash.
- Change the current working directory to your local project.
- Initialize the local directory as a Git repository.
$ git init
- Add the files to your new local repository. This stages them for the first commit.
$ git add
# Adds the files in the local repository and stages them for commit. To unstage, a file, use 'git reset HEAD YOUR-FILE'.
- Commit the files that you've staged in your local repository.
$ git commit -m "First commit"
# Commits the tracked changes and prepares them to be pushed to a remote repository. To remove this commit and modify the file, use 'git reset --soft HEAD~1' and commit and add the file again.
- At the top of your GitHub repository's Quick Setup page, click to copy the remote repository URL.
- In the Command prompt, add the URL for the remote repository where your local repository will be pushed.
- Push the changes in your local repository to GitHub.
$ git remote add origin remote repository URL
# Sets the new remote
$ git remote -v
# Verifies the new remote URL
$ git push origin master
# Pushes the changes in your local repository up to the remote repository you specified as the origin
Here I demonstrated how to create a git repository using two methods: git init and git clone. All the processes we have done here had been achieved by using the command line.
Instead of using the command line, we can also use Graphic User Interface software i.e GUI named Github desktop.
we can use GitHub Desktop to manage your projects, create meaningful commits, keep the project up-to-date, and review your preferred settings and track the project’s history in an app instead of on the command line.