Skip to main content

Create a repo

To put your project up on GitHub, you will need to create a repository for it to live in.

Create a repository

You can store a variety of projects in GitHub repositories, including open source projects. With open source projects, you can share code to make better, more reliable software. You can use repositories to collaborate with others and track your work. For more information, see "About repositories." To learn more about open source projects, visit OpenSource.org.

Notes:

  • You can create public repositories for an open source project. When creating your public repository, make sure to include a license file that determines how you want your project to be shared with others. 为深入了解开源,特别是如何创建和发展开源项目,我们制作了开源指南,它将通过推荐关于创建和维护开源项目存储库的最佳实践,帮助你培养一个健康发展的开源社区。
  • 还可以免费学习 GitHub Skills 课程来维护开源社区。
  • You can also add community health files to your repositories, to set guidelines on how to contribute, keep your repositories safe, and much more. For more information, see "Creating a default community health file."
  1. 在任何页面的右上角,使用 下拉菜单选择“新建存储库”。 包含创建新存储库选项的下拉菜单
  2. Type a short, memorable name for your repository. For example, "hello-world". Field for entering a repository name
  3. Optionally, add a description of your repository. For example, "My first repository on GitHub." Field for entering a repository description
  4. 选择仓库可见性。 有关详细信息,请参阅“关于存储库”。 用于选择存储库可见性的单选按钮
  5. 选择“使用 README 初始化此存储库”。 “使用自述文件初始化此存储库”复选框
  6. 单击“创建存储库”。 创建存储库的按钮

Congratulations! You've successfully created your first repository, and initialized it with a README file.

若要详细了解 GitHub CLI,请参阅“关于 GitHub CLI”。

  1. In the command line, navigate to the directory where you would like to create a local clone of your new project.
  2. To create a repository for your project, use the gh repo create subcommand. When prompted, select Create a new repository on GitHub from scratch and enter the name of your new project. If you want your project to belong to an organization instead of to your personal account, specify the organization name and project name with organization-name/project-name.
  3. Follow the interactive prompts. To clone the repository locally, confirm yes when asked if you would like to clone the remote project directory.
  4. Alternatively, to skip the prompts supply the repository name and a visibility flag (--public, --private, or --internal). For example, gh repo create project-name --public. To clone the repository locally, pass the --clone flag. For more information about possible arguments, see the GitHub CLI manual.

Commit your first change

A commit is like a snapshot of all the files in your project at a particular point in time.

When you created your new repository, you initialized it with a README file. README files are a great place to describe your project in more detail, or add some documentation such as how to install or use your project. The contents of your README file are automatically shown on the front page of your repository.

Let's commit a change to the README file.

  1. In your repository's list of files, click README.md. README file in file list
  2. Above the file's content, click .
  3. On the Edit file tab, type some information about yourself. New content in file
  4. 在新内容的上方,单击“预览更改”。 “文件预览”按钮
  5. Review the changes you made to the file. You will see the new content in green. File preview view
  6. 在页面底部,输入一条简短、有意义的提交消息,描述您对文件所作的更改。 您可以在提交消息中将提交归于多个作者。 有关详细信息,请参阅“创建具有多个共同作者的提交”。 更改的提交消息
  7. 在提交消息字段下面,确定是要将提交添加到当前分支还是新分支。 如果当前分支是默认分支,则应选择为提交创建新分支,然后创建拉取请求。 有关详细信息,请参阅“创建新的拉取请求”。 提交分支选项
  8. 单击“提议文件更改”。 提议文件更改按钮

Now that you have created a project, you can start committing changes.

README files are a great place to describe your project in more detail, or add some documentation such as how to install or use your project. The contents of your README file are automatically shown on the front page of your repository. Follow these steps to add a README file.

  1. In the command line, navigate to the root directory of your new project. (This directory was created when you ran the gh repo create command.)

  2. Create a README file with some information about the project.

    echo "info about this project" >> README.md
  3. Enter git status. You will see that you have an untracked README.md file.

    $ git status
    
    Untracked files:
      (use "git add ..." to include in what will be committed)
      README.md
    
    nothing added to commit but untracked files present (use "git add" to track)
  4. Stage and commit the file.

    git add README.md && git commit -m "Add README"
  5. Push the changes to your branch.

    git push --set-upstream origin HEAD

Next steps

You have now created a repository, including a README file, and created your first commit on GitHub.com.

  • You can now clone a GitHub repository to create a local copy on your computer. From your local repository you can commit, and create a pull request to update the changes in the upstream repository. For more information, see "Cloning a repository" and "Set up Git."
  • You can find interesting projects and repositories on GitHub and make changes to them by creating a fork of the repository. 为存储库创建分支可以在不影响原始存储库的情况下更改另一个存储库。 有关详细信息,请参阅“为存储库创建分支”。

  • GitHub 中的每个仓库均归个人或组织所有。 您可以在 GitHub 上连接和关注人员、仓库和组织以与之进行交互。 有关详细信息,请参阅“社交化”。

  • GitHub 有一个强大的支持社区,你可以在那里寻求帮助并与来自世界各地的人交谈。 加入 GitHub Community 上的对话。