git and github build and use tutorial under linux

Posted by 2oMst on Thu, 13 Jan 2022 21:18:55 +0100

1: Building git and github under linux

1. Registered gihub account:

github official website: You can create it yourself.
Log in, create repository, create a new warehouse, and create a test library test. The creation is complete.

2. linux Installation git environment

yum -y install git

3. Generate ssh key

The SSH keygen command generates the key, which can be directly defaulted, or you can choose your own encryption method, such as rsa encryption method

ssh-keygen -t rsa

Press enter all the time by default, and the generation is as follows
The production key is produced in the home directory In the ssh directory, view the public key:

cat ./ssh/

4. Add public key in github

Log in to github and add the public key address in the option setting > > SSH and GPG key > > add new SSH.
Just fill in the title

After adding, use ssh -T Command to detect success.

ssh -T

The following message indicates success.

[root@localhost ]# ssh -T
Hi ! You've successfully authenticated, but GitHub does not provide shell access.
[root@localhost ]#

5. Configure username and email of git parameter

This is because Git is a distributed version control system, so every machine must report its home: your name and Email address.

git config --global "your name"   //Configure user name
git config --global "your email"    //Configure email 

After configuration, you can view relevant parameters

 git config -l

2: Git is uploaded from the local repository to GitHub

1. Create and enter a directory as a local library

Here, take the testdir directory as an example to create readme MD file as an example.

 mkdir testdir && cd testdir

Initialize a local library

git init 

After initialization, a hidden folder will appear in this directory get

2. Add local libraries and push code files

Add files to local warehouse

git add 

Submit to the local library and note that the change is still local at this time.

git commit -m "first commit"

Add an alias of the remote server, which is also the name of the local warehouse. The format is:
remote add alias username / warehouse name git
Add an alias test here_ Readme, the user name is theonyu, and the warehouse name is test.

git remote add test_readme

Submit the local file (alias just now) to GitHub's test library. At this time, the local changes are updated to the GitHub service

git push -u test_readme master

Submitted successfully:
Check in github and the file has been uploaded successfully

Other command references are as follows:

git add #Add files to local warehouse
git rm #Delete in local warehouse
git commit -m "first commit" #Submit to the local library and note that the change is still local at this time.
git commit -a  ##Automatically update changed files, a can be understood as auto
git remote add xxx  #Add an alias for the remote server.
git remote rm xxx   ##Delete alias for remote version Library
git push -u remotename master #Submit the local file to GitHub's remoname version library. At this time, the local changes are updated to the GitHub service

3: Synchronize github to local repository

In the github repository, you can see the code option on the right. There are three ways
Generally, ssh can be used in linux, such as the readme just uploaded MD download to local

git clone

After downloading, the current directory exists as a folder with the warehouse name.

Download method difference reference:

git clone git:// ## is cloned locally in gitreadonly mode and can only be read
git clone  ##It is cloned locally by SSH and can be read and written
git clone ## is cloned locally by https and can be read and written
git fetch  ##Get local without merging
git pull ##Get and merge content locally

4: Branch management of GitHub

1. Create branch

Example: create a branch in the local warehouse directory Txt is submitted as a branch.

git branch #Displays whether the current branch is master
git branch new-txt  #Create a branch named new TXT
git checkout new-txt  #Switch to new branch
touch branch.txt
git add branch.txt
git commit -a -m "added branch.txt"
git push test_readme new-txt  ##Submitting the branch to the remote server only submits the branch structure and content to the remote server without merging with the trunk.

In the upper left corner of github, you can see that the new TXT branch has been uploaded successfully, and the file also exists. The master does not have a new file because it has not been merged.

2. Merge branch

If the new feature branch is mature, I think it is necessary to merge it into the master

git checkout master  #Switch to new backbone
git merge new-txt  ##Merge branches into trunk
git branch #Displays whether the current branch is master
git push test_readme master #At this time, the new TXT code, test, is also merged in the trunk_ Readme is the warehouse name

Successfully merged in github, the new file branch Txt also exists.

3. Other commands:

#Update remote branch list
git remote update Warehouse alias --prune

#View all branches
git branch -a

#Delete remote branch
git push Warehouse alias --delete Branch name

#Delete local branch
git branch -d Branch name

Topics: Linux Operation & Maintenance git github