YouTip LogoYouTip

Git Create Repository

# Git Create Repository In this chapter, we will introduce how to create a Git repository. You can use an existing directory as a Git repository. * * * ## git init Git uses the **git init** command to initialize a Git repository. Many Git commands need to be run inside a Git repository, so **git init** is the first command you use when starting with Git. After executing the **git init** command, a .git directory will be created in the repository. This directory contains all the metadata for the resources, while the other project directories remain unchanged. ### Usage Navigate to the directory where you want to create the repository, or create a new directory first: mkdir my-project cd my-project Use the current directory as the Git repository; we just need to initialize it. git init After executing this command, a .git directory will be generated in the current directory. Use a specified directory as the Git repository. git init newrepo After initialization, a directory named .git will appear in the newrepo directory. All the data and resources needed 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 first need to use the git add command to tell Git to start tracking these files, and then commit them: $ git add *.c $ git add README $ git commit -m 'initial project version' The above commands will commit the files ending with .c and the README file in the directory to the repository. > **Note:** In Linux systems, commit messages use single quotes ', while in Windows systems, commit messages use double quotes ". > > > Therefore, in git bash, `git commit -m 'commit message'` works, but in the Windows command line, you need to use double quotes: `git commit -m "commit message"`. * * * ## git clone We use **git clone** to copy a project from an existing Git repository (similar to **svn checkout**). The command format for cloning a repository is: git clone If we need to clone into a specified directory, we can use the following command format: git clone **Parameter Description:** * **repo:** Git repository. * **directory:** Local directory. For example, to clone the Git code repository for the Ruby language, Grit, you can use the following command: $ git clone git://github.com/schacon/grit.git After executing this command, a directory named grit will be created in the current directory, containing a .git directory to save all downloaded version records. If you want to define the name of the new project directory yourself, you can specify the new name at the end of the above command: $ git clone git://github.com/schacon/grit.git mygrit ## Configuration Git settings are configured 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 git configuration file: $ git config -e # For the current repository Or: $ git config -e --global # For all repositories on the system Set user information for committing code: $ git config --global user.name "tutorial" $ git config --global user.email test@ If you omit the **--global** parameter, it only applies to the current repository. * * *
← Python Count Occurrences ElemePython Clear List β†’