How to create a git repository? Step by Step instructions

Total
0
Shares

In this article I will show you the step by step instructions to create a git repository.

git init

Git uses the git init command to initialize a Git repository. Many Git commands need to be run in the Git repository, so git init is the first command to use Git.

After executing the git init command, the Git repository will generate a .git directory that contains all metadata of the resource, and other project directories remain unchanged.

Instructions

Using the current directory as the Git repository, we just need to initialize it.

git init

After the command is executed, a .git directory will be generated in the current directory.

Use the directory we specified as the Git repository.

git init newrepo

After initialization, a directory named .git will appear in the newrepo directory, and all data and resources required by Git are stored in this directory.

If there are several files in the current directory that you want to include in version control, you need to use the git add command to tell Git to start tracking these files, and then commit:

$ git add *.c
$ git add README
$ git commit -m 'initialize project version'

The above command submits the directory ending with .c and the README file to the warehouse.

Note: In Linux systems, the commit information uses single quotation marks ' , and on Windows systems, the commit information uses double quotation marks " .

So in git bash, git commit -m 'commit description' is OK, and double quotes git commit -m "commit description" should be used on the Windows command line .


git clone

We use git clone to copy the project from an existing Git repository (similar to svn checkout ).

The command format for cloning a repository is:

git clone <repo>

If we need to clone to a specified directory, we can use the following command format:

git clone <repo> <directory> 

Parameter Description:

  • repo: Git repository.
  • directory: local directory.

For example, to clone the facebook react library, use the following command:

$ git clone [email protected]:facebook/react.git

After executing this command, a directory named react will be created in the current directory, which contains a .git directory for saving all downloaded version records.

If you want to define the name of the new project directory yourself, you can specify a new name at the end of the above command:

$ git clone [email protected]:facebook/react.git myReactProject

configure

git is set up using the git config command. Display current git configuration information:

$ git config --list
credential.helper=osxkeychain
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true

Edit the git configuration file:

$ git config - e     # for the current repository

or:

$ git config -e --global # for all repositories on the system   

Set user information when submitting code:

$ git config --global user.name "techinplanet" 
$ git config --global user.email [email protected]

If the –global parameter is removed, it is only valid for the current project.

Conclusion

In this article we saw how to create a git repository from git init command to committing the first file. We see how to use git clone and check configuration using git config command.

Leave a Reply

Your email address will not be published. Required fields are marked *