创建git repo

简介: http://git-scm.com/book/en/Git-Basics-Getting-a-Git-Repository Getting a Git Repository You can get a Git project using two main approaches.

http://git-scm.com/book/en/Git-Basics-Getting-a-Git-Repository

Getting a Git Repository

You can get a Git project using two main approaches. The first takes an existing project or directory and imports it into Git. The second clones an existing Git repository from another server.

Initializing a Repository in an Existing Directory

If you’re starting to track an existing project in Git, you need to go to the project’s directory and type

$ git init

This creates a new subdirectory named .git that contains all of your necessary repository files — a Git repository skeleton. At this point, nothing in your project is tracked yet. (See Chapter 9 for more information about exactly what files are contained in the .git directory you just created.)

If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:

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

We’ll go over what these commands do in just a minute. At this point, you have a Git repository with tracked files and an initial commit.

Cloning an Existing Repository

If you want to get a copy of an existing Git repository — for example, a project you’d like to contribute to — the command you need is git clone. If you’re familiar with other VCS systems such as Subversion, you’ll notice that the command is clone and not checkout. This is an important distinction — Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. In fact, if your server disk gets corrupted, you can use any of the clones on any client to set the server back to the state it was in when it was cloned (you may lose some server-side hooks and such, but all the versioned data would be there — see Chapter 4 for more details).

You clone a repository with git clone [url]. For example, if you want to clone the Ruby Git library called Grit, you can do so like this:

$ git clone git://github.com/schacon/grit.git

That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:

$ git clone git://github.com/schacon/grit.git mygrit

That command does the same thing as the previous one, but the target directory is called mygrit.

Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. Chapter 4 will introduce all of the available options the server can set up to access your Git repository and the pros and cons of each.

目录
相关文章
|
19天前
|
项目管理 开发工具 Android开发
repo跟git的关系
Repo与Git不是替代关系,而是相互补充。Git关注于单个仓库的版本控制,而Repo在此基础上提供了一套管理多个Git仓库的框架,特别适合处理大规模、多组件协同开发的项目。通过Repo,开发者可以更高效地处理复杂的项目结构,同时享受Git带来的版本控制优势,两者结合,为大型软件项目管理提供了强大的支撑。
54 1
|
开发工具 git
Git - 拉取远程分支并创建本地分支(一)
Git - 拉取远程分支并创建本地分支(一)
602 0
|
存储 开发工具 Android开发
git repo工具详细使用教程
git repo工具详细使用教程
|
程序员 开发工具 git
Git中的分支---查看,创建,切换
Git中的分支---查看,创建,切换
203 1
Git中的分支---查看,创建,切换
|
开发工具 git
Git创建----远程仓库操作(GitHub版)
git工具中粘贴是: shift + insert shift + insert shift + insert (★★)
125 0
Git创建----远程仓库操作(GitHub版)
|
安全 开发工具 数据库
Git创建-----本地仓库(GitHub版)
先在特定目录下创建一个.git
144 0
Git创建-----本地仓库(GitHub版)
|
Shell 网络安全 开发工具
利用Git工具将本地创建的项目上传到Github上
利用Git工具将本地创建的项目上传到Github上
132 0
利用Git工具将本地创建的项目上传到Github上
|
Shell 网络安全 开发工具
Git中添加密钥&&ssh密钥的创建与查看(打开id_rsa.pub文件)
Git中添加密钥&&ssh密钥的创建与查看(打开id_rsa.pub文件)
Git中添加密钥&&ssh密钥的创建与查看(打开id_rsa.pub文件)
Git_IDEA集成git_创建分支&切换分支
Git_IDEA集成git_创建分支&切换分支
288 0
Git_IDEA集成git_创建分支&切换分支
|
网络安全 开发工具 git
Git_码云_账号的注册登录&创建远程库
Git_码云_账号的注册登录&创建远程库
243 0
Git_码云_账号的注册登录&创建远程库