How do I create files from GitHub

2.1 Git basics - Create a Git repository

If you can / want to work through just one chapter to get started with Git, this is the one. This chapter covers all of the basic commands you need to do the vast majority of the tasks you will eventually do with Git. At the end of the chapter you should be able to create and configure a new repository, versioning or removing files from version management, adding files to the staging area and finally performing a commit. It also shows how to configure Git to ignore certain files and file patterns, how to quickly and easily undo mistakes, how to search a project's history and look up changes between commits, and how to retrieve data from a remote repository can download or upload there.

Create a Git repository

You have two options for creating a Git repository on your computer.

  1. You can turn a local directory that is not currently under version control into a Git repository, or

  2. You can get an existing Git repository from another location clone.

In both cases, you get a ready-to-use Git repository on your local machine.

Set up a repository in an existing directory

If you have a project directory that is not currently under version control and you want to start taking control of Git, you must first switch to that project's directory. If you've never done this before, it will look a little different depending on which system you're using:

and enter the following command there:

The command creates a subdirectory that contains all relevant Git repository data, i.e. a Git repository framework. No files are versioned in Git at this point. See Chapter 10, Git Internals, for more information on what files are in the directory and what their purpose is.

If you want to version existing files (and it is not just an empty directory), you should start the current status in an initial commit. With the command you specify which files are to be versioned and with the command you create a new commit:

We'll go into these commands in more detail in a moment. For now, the only important thing is that you understand that you have now created a Git repository and made an initial commit.

Clone an existing repository

If you want to create a copy of an existing Git repository - for example to work on a project - you can use the command. If you already have experience with another VCS system such as Subversion, you will immediately notice that the command is “clone” and not “checkout”. This is an important difference that you should definitely understand. Instead of just creating a simple working copy of the project, Git loads almost all of the data that the server holds onto the local computer. Each version of each project history file is automatically downloaded when you run. If your server hard drive becomes damaged, you can use almost any of the clones on any client to restore the server to the state it was in when it was cloned. (You might lose some server-side hooks and the like, but all versioned data would be there - see Chapter 4, Git on the Server, for more details.)

You can clone a repository with the command. For example, to clone the Git linkable library repository, run the following command:

Git then creates a directory, initializes a directory in this, downloads all data from the repository and checks out a working copy of the latest version. If you change to the new directory, you will find the project files there and can work with them straight away.

If you want to clone the repository to a directory with a different name, you can do that as follows:

This command does the same as the previous one, but this time the target directory is.

Git supports a number of different transmission protocols. The previous example uses the protocol, but you can also encounter the information or which the SSH transfer protocol uses. Chapter 4, Git on the Server, introduces all of the options the server has for accessing your Git repository and the pros and cons of each option you can set up.