A Git repository may be created in one of two ways: you can convert a local directory that is not presently under version control into a Git repository or clone an existing Git repository from another location.
You'll have a working Git repository on your local system in any instance.
If you wish to start using Git to control a project directory that is presently not under version control, you must first travel to that project's directory. If you've never done this before, the process appears somewhat different depending on the operating system you're using:
for Linux users:
$ cd /home/user/my_project for macOS: $ cd /Users/user/my_project for Windows: $ cd C:/Users/user/my_project and type: $ git init
A Git repository skeleton is created by creating a new subfolder named.git that contains all of your essential repository files. Nothing in your project is currently being monitored. More information about the files in the.git directory you just created may be found in Git Internals.
If you wish to start version-controlling actual files (rather than an empty directory), you should start tracking them and commit them first. You may do this by using a couple git add commands to indicate the files you wish to track, then commit the changes:
$ git add *.c $ git add LICENSE $ git commit -m 'Initial project version'
In a moment, we'll go through what these instructions accomplish. You have a Git repository with tracked files and an initial commit at this point.
The command git clone is used to obtain a copy of an existing Git repository, such as a project you'd like to contribute. You'll note that the command is "clone" rather than "checkout" if you're acquainted with other VCSs like Subversion. This is a key distinction: Git obtains a complete copy of the server's data rather than receiving only a working copy. When you run git clone, it pulls down every version of every file in the project's history by default. If your server disc becomes corrupted, you can often restore the server to the state it was in when it was cloned by using nearly any of the clones on any client (you'll lose some server-side hooks and such, but all the versioned data will be there — see Getting Git on a Server for more information).
Git clone url> is used to clone a repository. If you wish to clone the Git linkable library libgit2, for example, follow these steps:
https://github.com/libgit2/libgit2 $ git clone
This builds a libgit2 directory, creates a.git directory within it, pulls down all the data for that repository, and checks out a functioning copy of the newest version. If you browse to the newly formed libgit2 directory, you'll find the project files there, ready to be worked on or utilised.You can give the new directory name as an additional parameter if you wish to clone the repository into a location other than libgit2.
$ git clone https://github.com/libgit2/libgit2 mylibgit
The target directory for this command is named mylibgit, and it performs the same thing as the previous one.
You may utilise a variety of transfer protocols with Git. The https:// protocol is used in the preceding example, but you may also see git:/ or user@server:path/to/repo.git, which utilises the SSH protocol. In Getting Git on a Server, you'll learn about all of the many ways your server may access your Git repository, as well as the benefits and drawbacks of each.