Git ~ Set up a repository - rohit120582sharma/Documentation GitHub Wiki

A Git repository is a virtual storage of your project. It allows you to save versions of your code, which you can access when needed.

Initializing a new repository

The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new, empty repository.

It is a one-time command you use during the initial setup of a new repo. Executing this command will create a new ".git" sub-directory in your current working directory, which contains all of the necessary Git metadata for the new repository. This will also create a new master branch.

$ cd /path/to/your/existing/code
$ git init

Cloning an existing Git repo

If a project has already been set up in a central repository, the git clone <repo-url> command is used to obtain a local development copy. The central repository can be local or remote.

Internally, git clone first calls git init to create a new repository. It then copies the data from the existing repository, and checks out a new set of working files.

Cloning automatically creates a remote connection called "origin" pointing back to the original repository. This makes it very easy to interact with a central repository.

# git clone <remote_repo_url>
$ git clone https://github.com/rohit120582sharma/Angular-2.git

# start working on the project
$ cd <my-project>

Configuring a Git repo for remote collaboration

If you used git init to make a fresh repo, you'll have no remote repo (central repository) to push changes to. Once you have created a remote repo, you will need to update your local repo with a mapping.

The git remote command will map remote repository at <remote_repo_url> to a ref in your local repo under <remote_name>.

# git remote add <remote_name> <remote_repo_url>
$ git remote add origin https://github.com/rohit120582sharma/Angular-2.git

Once you have mapped the remote repo you can push local branches to it.

# git push <remote_name> <local_branch_name>
$ git push origin master


⚠️ **GitHub.com Fallback** ⚠️