Git and GitHub Practice __git

Source: Internet
Author: User
Tags create directory svn using git

Software development can not be separated from version control, the development of n years, the use of a lot of version control tools, from VSS (some people evaluate the tool against human design), to CVS,SVN have been used. But these tools are central, with the development of the Internet and technology, distributed version control tools are more and more popular, the most famous one is Git. The biggest drawback of centralized versioning tools is that all engineering-related personnel will be affected as soon as they crash, and distributed version management is a complete version of each machine. In addition, Git is also praised by users for managing version branches.

GitHub is an open, Git-based version of the Internet library that describes git and github practices

The objective and content of this practice:

1, build a Linux environment git use

2. Git basic command

3. Use Git and GitHub

4, build private git library

Two, git use and command introduction

1. Under Linux, verify that git is installed, enter git instructions, and if the following Help interface appears, Git has been installed. If installation is not installed by Yum: Yum install git

2, create git library user, under the root account, use the following command

Create User: AddUser git

Modify user password: passwd git

3. Create user for Git tool

git config--global user.email "Enter registered mailbox" git config--global user.name "Enter registered user"

4. Git initialization

Create a repository for git and select a catalog for inventory:/opt/cwqsologit

Execute instructions in this directory: Git init

The local library uses Git init, and if you are creating a remote library, use git init--bare


5, git upload file and submit

Create a Readme file in this directory to upload this file to git

[Root@cwqsolo cwqsologit]# git  add  readme

[Root@cwqsolo cwqsologit]# git  commit-  m   Readme

[Root@cwqsolo cwqsologit]# git add readme
[Root@cwqsolo cwqsologit]# git commit-m  "Append notes"
[Master 658169E] Append Memo
 1 files changed, 3 insertions (+), 0 deletions (-)

A string of characters can be seen through the git log command, such as: C05F4B5BC3776AA50D879C03E8568B0B721715DF is computed by SHA1, and in distributed versioning, the ID of the presentation is not as simple as SVN. Now edit the Readme and add the new version

Description:
  This git library was created in January 2018

maintenance Staff:
  Cwqsolo

Note:
  Just test end

:

Add and commit again, and through git log we can see a new section of the record, with a fresh string

6. Git version recovery

[Root@cwqsolo cwqsologit]# git  reflog
38f7635 head@{0}: Commit:append end
658169e head@{1}: Commit: Append Note
c05f4b5 head@{2}: Commit (initial): Readme

Let's go back to the first version and then "Shing" back to the last version.
[Root@cwqsolo cwqsologit]# 
[root@cwqsolo cwqsologit]# git  reset  --hard  c05f4b5
head are now at C05F4B5 Readme
[Root@cwqsolo cwqsologit]# ls
readme
[Root@cwqsolo cwqsologit]# cat  Readme
Description:
  This git library was founded in January 2018

Maintenance personnel:
  Cwqsolo
[root@cwqsolo cwqsologit]# git  reset  --hard  38f7635
Head are now in 38f7635 append  end
[Root@cwqsolo cwqsologit]# 
[Root@cwqsolo cwqsologit]# 
[ Root@cwqsolo cwqsologit]# Cat  Readme
Note:
  This git library was created in January 2018 by

Maintenance personnel:
  Cwqsolo

notes:
  Just Test end

:

The above operation illustrates git, and the various fallback and recovery versions are very convenient and easy

7. Working area and registers

Here are some actions to understand the concept of Git's workspace and registers. Create a new file,

[Root@cwqsolo cwqsologit]# VI  my.conf

logpath=/opt/dev
filename=bi.log
Then revise the readme, add a time after the end, and then look at the git status command
[Root@cwqsolo cwqsologit]# git status
# on branch Master
# Changed but no updated:
#   (use) git add <fi Le> ... "To update what'll be committed)
#   (use" Git checkout-<file> ... "to discard changes in Workin G directory)
#       modified:   Readme #
untracked files: # (use)   git add < File>.. "To include in what would be committed)
#
#       my.conf
no changes added to commit (use" Git "ad D "and/or Git commit-a")
With the git add command, two files are added
[Root@cwqsolo cwqsologit]# git  status
# on branch Master
# Changes to is committed:
#   (use) git Reset Head <file> ... "to Unstage" #       new file:   my.conf
#       modified:   Readme
#
This time from the workspace, into the registers, through the commit instruction can be submitted to the master of the staging area
[Root@cwqsolo cwqsologit]# git  commit-m  "two files"
[master 4327027] Two files
 2 files changed, 3 insert Ions (+), 1 deletions (-)
 Create mode 100644 my.conf
[Root@cwqsolo cwqsologit]# 
[Root@cwqsolo cwqsologit]# 
[Root@cwqsolo cwqsologit]# git status
# on branch Master No to
commit (working directory clean)
After the commit, the workspace was cleaned up again. Workspace-Stage (staging area)-"Master"

8. git file deletion

Rm:remove regular file ' my.conf '? Y
[root@cwqsolo cwqsologit]# ls  -ltr total
4
-rw-r--r--1 root root, Feb 22:02 readme
[Root@cwq Solo cwqsologit]# 
[Root@cwqsolo cwqsologit]# 
[Root@cwqsolo cwqsologit]# 
[Root@cwqsolo cwqsologit]# git  Status
# on branch Master
# Changed but ' not updated:
#   [use ' Git add/rm <file>. ' To update What'll be committed]
#   (use "Git checkout-<file> ..." to discard changes in working directory)
#       deleted:    my.conf
#
No changes added to commit (use "git add" and/or "Git Commit-a")

1) mistakenly deleted, need to be my.conf back, you can execute the following command git checkout--file my.conf
[Root@cwqsolo cwqsologit]# git  checkout-  -  my.conf
[Root@cwqsolo cwqsologit]# 
[ Root@cwqsolo cwqsologit]# 
[root@cwqsolo cwqsologit]# ls
my.conf  Readme

2 true Delete, we want to delete the my.conf inside the library
[Root@cwqsolo cwqsologit]# git  rm  my.conf
rm ' my.conf '
[Root@cwqsolo cwqsologit]# git  commit -  m "del  my.conf"
[master 245d7d4] del  my.conf
 1 files changed, 0 insertions (+), 2 deletions (-)
 Delete mode 100644 my.conf
[Root@cwqsolo cwqsologit]# 
[Root@cwqsolo cwqsologit]# git  status
# on branch Master No to
Commit (working directory clean)

In addition git also has push,pull, remote and so on instruction, in the follow-up practice will use

Iii. use of GitHub

The front is the local establishment of warehouses and operations, but agreed to distribute it. How to facilitate the synergy between us. This is GitHub, an internet-provided git warehouse hosting service that allows you to obtain a git remote repository by registering a GitHub account:

1 for the development of the Code farmers anywhere, the Internet warehouse operation more convenient (of course, security issues)

2 Do not consider the local warehouse to occupy the hard drive

Disadvantage: The content on the Internet, public, so can not put the security requirements high on the GitHub. So GitHub is a natural customization for open source software. GitHub's web site is https://github.com/

Under the pop-up page, we create a library of our own

Click Create, build your own library, and provide the address of the library on this page. Note that this is the Internet library, when submitting, do not put the enterprise confidential to go up.

This page also provides an operational guide to all of us to see

Git init
git add readme.md
git commit-m "the" "The" "The" "The" "The" ""
T
git push-u Origin Master 


Four, private git warehouse practice

The development of enterprise-class applications, will consider code security issues, so it is necessary to build a Git server within the enterprise, the scenario described below:

Private library Environment: Two machines: 192.168.136.144 and 192.168.136.177, all CentOS operating systems, 6.5 and 7.0 respectively

Set up a private library goal: Simulate creating a git server warehouse on 144, then build git local warehouses in 144 and 177, and finally generate files in the 144 and 177 local warehouses and push them to the server warehouse

The recommended steps to build a private git server are as follows

1, related services 144,177 install git

The CentOS installation can be yum by way of: Yum install git. After the installation is successful, execute git instructions, and the following interface is displayed to indicate successful installation.


2, create user and production password

Create Git users on both 144 and 177

AddUser git

passwd git to enter 2 times password according to the interface prompts Git1qaz

3, collect the client's key, store it to git server, and add it to Git's key file.

1 The client generates the key, for example

144 on the host ssh-keygen-t rsa-c "cwqsolo@163.com"

177 on the host ssh-keygen-t rsa-c "177user@qq.com"

2 Copy the 177 generated password to the 144 git server

3 Append the password file to git server/home/git/.ssh/authorized_keys file

The following step is on the GIT server, using Git user action, cat id_dsa.pub >> ~/.ssh/authorized_keys

4. Server Warehouse creation and initialization

Create a directory on 144/opt/cwqsolo.git This directory as a server warehouse, enter this directory, use the following command to initialize

git init--bare or git init--bare/opt/cwqsolo.git

Operation directory under/opt/cwqsolo.git, two instructions are the same.

5. Local warehouse creation and initialization

144: Create directory/opt/local144.git, enter this directory, with command git init for initialization (there is no--bare parameter)

177: Create directory/opt/local177.git, enter this directory, with command git init for initialization (there is no--bare parameter)

6, modify the permissions of each warehouse

Execute on 114

Chown-r Git:git/opt/cwqsolo.git

Chown-r Git:git/opt/local144.git

Execute on 177

Chown-r Git:git/opt/local177.git

The above actions assign the permissions of these directories to the GIT user
7, in the local directory to specify the corresponding server warehouse

You can specify a remote server repository by executing the following command: Git remote add Origin git@192.168.136.144/opt/cwqsolo.git

8, 177 new file my.conf pushed into the warehouse

git add my.conf

Git commit-m "new file my.conf"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.