[Git] How to create a repository

♠ Posted by NN TRUNG at 18:15
Repository (repository) that is where you will store source and one other person can copy (clone) the source code to work. Repository has two types of Local Repository (repository on a single computer) and Remote Repository (repository on a remote server).
In this article, I will guide you how to create local and remote repository repository (using Github) and work with it.

Create local repository

Firstly, to create a repository, you need access to the source directory with the command cd , then use the command git init to initialize the repository in that directory. In this example, I will create a new folder to contain the latter and initialization code repository for it, I would use the git init tên_folder to it automatically starts to create folders.
  $ Git init git_example
 Git repository empty initialized in /home/thachpham/git_example/.git/ 
In the paragraphs above, it displays the message I was initialized empty Git repository in the path as shown above. Note that hidden folders .git/ where it will contain the settings of Git and saved all information about storage, you do not need to touch anything in the directory .git/ this.
If your repository is available on the source then you need to put the files on TRACKED state to be able to work with Git. To do this, you will need to use the command git add tên_file , may use the mark *to fit all. Then use the command git status to see a list of files that were tracked.
  $ Git add readme.txt
 $ Git status
 On branch master 
  Initial commit 
  Changes to be Committed:
  (Use "git rm --cached <file> ..." to unstage) 
  new file: readme.txt 
And after the file has been put into the state tracked and if a file has tracked it must be put into the Staging Area (explained later) and with the command git add , you can proceed Trust ( commit) to save the capture of the change. Structured command will commit git commit -m "Lời nhắn" , this time all the files are in a state tracked (new files) or a file has been tracked, but there is a new change, it will commit.
  $ Git commit -m "First Commit"
 [Master (root-commit) 799db56] First Commit
  1 files changed, 0 insertions (+), 0 deletions (-)
  create mode 100644 readme.txt 
Now that you have completed the first commit files that you've put into the store, I'll say more about the commit in future articles. Bottom line is that here you have a Git source code repository on your machine.

Create a repository on Github and work

First, you need to log in to Github , then clicking on the + sign on the menu and select New repository.
github-create-repository
You will need to name your repository. You can select the type of storage is Public (anyone can clone) and Private (only those authorized can clone).
github-create-repository-02
Fill out the information when creating Repository on Github
Once you've created it will lead you to a page to guide work with the newly created repository. And your repository will now address the https://github.com/$user-name/$repository , eghttps://github.com/thachphamblog/hoc-git .
Your job now is to clone the repositories on your machine using the command git clone địa_chỉ .
  $ Git clone https://github.com/thachphamblog/hoc-git
 Cloning Into 'hoc-git' ...
 warning: You vẻ to have cloned an empty repository.
 Checking connectivity ... done 
Now visit the working directory tree (just clone the repository folder on) and try to create a file namedREADME.md, then use the command git add to put the files into the Staging Area.
  $ Cd hoc-git
 $ Echo "Git co Huong dan ban"> README.md
 $ Git add README.md
 $ Git commit -m "First commit on Github"
 [Master (root-commit) 6e729a4] First commit on Github
  1 files changed, 1 insertion (+)
  create mode 100644 README.md 
However after the commit is finished, the file was still unable to commit will appear on Github repository that you have to do one more thing that is taking command git push to push the file has been commit to Github. Note that you will need to enter the account and password Github.
  $ Git push origin master 
  Counting objects: 3, done.
 Writing objects: 100% (3/3), 244 bytes | 0 bytes / s, done.
 Total 3 (delta 0), reused 0 (delta 0)
 To https://github.com/thachphamblog/hoc-git
  * [New branch] master -> master 
origin means the name of the remote (see later) and master 's branch name, these two I will explain in more detail in its own article. Now you can check your repository on Github already.
github-create-repository-03
Result after the source code was commit push up Github
Maybe you'll see whenever push on Github, it will display a notice too wordy, you can give away hidden messages that only display the report on Github username and password, you can set with this command .
  git config push.default simple --global 
However if you do not like being asked for a password again, you can use SSH to Github, I would say this one later.

Epilogue

Now you know how to create a Git repository for now? It's simple is not it, now to continue the post after easier, be practical to create a file on your computer and reposity commit, or you can use Github to prefer putting their code into the repository for handy offline.

0 nhận xét:

Đăng nhận xét