Using git and github on Linux VM

  

1. What is GIT?

Git is a distributed version control/software configuration management software originally developed by Linux kernel developer Linus Torvalds for better Designed to manage Linux kernel development.

Advantages of Git compared to CVS/SVN:

- Support for offline development, offline Repository

- Powerful branching, suitable for collaboration with multiple independent developers

- Speed ​​Blocks

2. What is GITHUB?

GitHub is a shared web hosting service for storing software code and content items that are controlled using Git.

3.Using git and github on a Linux virtual machine

3.1 Registering a github account

This step is relatively simple and need not be described.

3.2 Virtual Machine Installation git Client

I am using the CentOS virtual machine, the installation command is as follows:

yum install git git-gui

3.3 Generate a key pair so that the project can be pushed onto github

[root@CentOS tuzhutuzhu]# ssh-keygen -t rsa -C "*****@**.com"

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):< Br>

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa .pub.

The key fingerprint is:

63:68:68:ad:23:0f:8f:85:4a:cc:67:60:47:9e:7a: Fa [email protected]

The key's randomart image is:

+--[ RSA 2048]----+

|  |

|  |

|  . |

|  o .o . |

|  o +o + S |

| + +o o . . |

|  =+++ |

| ..=B . |

| ..oEo |

+-----------------+

[root@CentOS tuzhutuzhu]#

3.4 will .ssh/id_rsa Copy .oub to GitHub

3.5 Test if you can connect to GitHub

[root@CentOS tuzhutuzhu]# ssh [email protected]

The authenticity of host 'github. Com (192.30.252.131)' can't be established.

RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df :a6:48.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'github.com,192.30.252.131' (RSA) to the List of known hosts.

Enter passphrase for key '/root/.ssh/id_rsa':

Permission denied (publickey).

[root@CentOS tuzhutuzhu]#

3.6 Setting Git Global User Configuration

# git config --global user.name "Firstname Lastname"

# git config --global user.email "your_email @youremail.com"

Here the user is called his or her actual name (custom), and Login User Name

3.7 Git Create a Repository

Create Complete:


3.8 Create a local new project repository. This step can be Follow the prompts on the web page after GitHub is created in the above diagram

# mkdir new-project(*1)

# cd new-project

# git init< Br>

# touch README

# git add README

# git commit -m 'first commit'

Defining the remote server alias origin

# git remote add origin [email protected]:***/new-project.git(*2)

Local and remote merge, local default branch is master

# git push origin Master

(*1) The repository name here must be the same as the repository name created in GitHub in 3.7

(*2) where *** is the username of GitHub

When performing a push operation, the following error may occur:

[root@CentOS vmware]# git push -u origin master

error: The requested URL returned error: 403 While accessing< Br>

fatal: HTTP request failed

This is because GitHub seems to only support ssh to access the repository. The solution is as follows:

1).vim .git/config

2). Set the url of the [remote "origin" section to the following format:

url = ssh://[email protected]/tuzhutuzhu/vmware.git

fetch = +refs/heads/*:refs/remotes/origin/*

Execute the push operation again, the result As follows:

[root@CentOS vmware]# git push -u origin master

Enter passphrase for key '/root/.ssh/id_rsa':

Counting objects: 7, done.

Delta compression using up to 2 threads.

Compressing objects: 100% (3/3), done.

Writing objects: 100% (7 /7), 548 bytes, done.

Total 7 (delta 0), reused 0 (delta 0)

To ssh://[email protected]/tuzhutuzhu/vmware.git

* [new branch] master -> master

Branch master set up to track remote branch master from origin.

[root@CentOS vmware]#

This will upload the file to GitHub.

Copyright © Windows knowledge All Rights Reserved