Home  >  Article  >  Development Tools  >  How to build github in linux

How to build github in linux

PHPz
PHPzOriginal
2023-04-26 09:13:481389browse

As the most popular code hosting platform in the open source community, the use of GitHub has become standard for modern software development. As one of the main tools for developers, Linux system is undoubtedly a good choice to build GitHub on Linux. This article will introduce how to set up and use GitHub on Linux.

Step one: Create a GitHub account

If you don’t have a GitHub account yet, you need to first create an account on the GitHub official website. There is no need to go into details about this operation, there are detailed instructions on the website.

Step 2: Install Git

Install Git through the command line under Ubuntu:

sudo apt-get update
sudo apt-get install git

Install Git through the command line under CentOS:

sudo yum install git

Step 3: Create an SSH key

GitHub uses SSH keys for user authentication and communication. Therefore, before using GitHub, you need to create an SSH key on your local machine.

Execute the following command on Linux:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

During the execution process, the system will prompt you to enter the storage path and password of the secret key, just press Enter. If you do not need password protection, just press the Enter key continuously.

The generated SSH key storage path defaults to ~/.ssh/id_rsa.pub. Use the cat command to view the public key.

cat ~/.ssh/id_rsa.pub

Copy the contents of the public key to your GitHub account's SSH key. Enter the GitHub website, click Settings on the menu bar, then select SSH and GPG keys, then copy the public key content to the interface for adding a key, and finally save it.

Step 4: Create a warehouse

Creating a warehouse on GitHub is very simple. Just click the New Repository button on the website and enter the warehouse name and related information.

Step 5: Clone the warehouse

Use the Git command on the local machine to clone the warehouse on the server:

git clone git@github.com:username/repo.git

Where username is your GitHub username, repo is the name of the warehouse you created.

Step 6: Add files and submit changes

Add or modify files in the cloned local warehouse, and then submit them through Git commands.

git add .
git commit -m "Add new file"
git push origin master

Among them, the add command will add the files you modified; commit will submit your changes, and the -m parameter is followed by a description of the submitted information as a comment; push will push your changes to GitHub In the warehouse. If you have multiple branches, you can specify the corresponding branch name in push.

Step 7: Create a branch

Use Git command to create a new branch:

git branch new-branch

where new-branch is the name of the new branch created.

Switch to the new branch:

git checkout new-branch

Add the modified files on the new branch and submit using Git:

git add .
git commit -m "Add new branch"
git push origin new-branch

Step 8: Merge branches

Merge the new-branch branch to the master branch:

git checkout master
git merge new-branch

Use the push command to push the merged code to GitHub:

git push origin master

So far, we have learned how to build it on Linux And use GitHub. Hope this article can be helpful to you!

The above is the detailed content of How to build github in linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to install githubNext article:How to install github