Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install and use Git and GitHub on Ubuntu Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to install and use Git and GitHub on Ubuntu Linux. It is very detailed and has a certain reference value. Friends who are interested must read it!

1. Install Git on Linux

Download and install Git:

Sudo apt-get install git

The above commands apply to Ubuntu and should work on all * * versions of Ubuntu. They have been tested on Ubuntu 16.04 and Ubuntu 18.04 LTS (Bionic Beaver) and should also work in future versions.

2. Configure GitHub

Once the installation is complete, the next step is to configure the GitHub user's configuration details. Please use the following two commands and be sure to replace user_name with your own GitHub user name and email_id with the email you created your GitHub account.

Git config-global user.name "user_name" git config-global user.email "email_id"

The following picture shows an example of how to configure the above command with my GitHub user name: "akshaypai" and my email address "abc123@gmail.com".

Git config

3. Create a local warehouse

Create a directory on your system. It will be used as a local repository, and later it will be pushed to the remote warehouse of GitHub. Use the following command:

Git init Mytest

If the directory is created successfully, you will see the following message:

Initialized empty Git repository in / home/akshay/Mytest/.git/

This line of information may vary depending on your system.

Here, Mytest is the directory created, and init converts it into a GitHub repository. Change the current directory to the newly created directory.

Cd Mytest4, create a new README file to describe the warehouse

Now create a README file and enter some text, such as "this is git setup on linux". README files are generally used to describe what the repository is used to place or what the project is about. For example:

Gedit README

You can use any text editor. I like to use gedit. The contents of the README file can be:

This is a git repo5, add the files in the warehouse to an index

This is a very important step. Here we will add an index to all the content that needs to be pushed to GitHub. This may include text files or applications that you added to the repository for the first time, or edits to existing files (an updated version of the file).

Now that we have the README file, let's create another file, such as a simple C program, which we call sample.c. The contents of the document are:

# includeint main () {printf ("hello world"); return 0;}

Now we have two files. README and sample.c.

Add them to the index with the following command:

Git add READMEgit add smaple.c

Note that the git add command can add any number of files and directories to the index. Here, when I say "index," I mean a buffer with a certain amount of space that stores all files or directories that have been added to the Git repository.

6. Add the changes to the index

After all the documents have been added, you can submit them. This means that you have identified the final file changes (or additions), and now they are ready to be uploaded to our own warehouse. Use the command:

Git commit-m "some_message"

"some_message" in the above command can be some simple information such as "my * submission" or "edited readme file", and so on.

7. Create a warehouse on GitHub

Create a warehouse on GitHub. Please note that the name of the warehouse must be exactly the same as the name of the warehouse you created locally. In this case, it's "Mytest". Please log in to your GitHub account first. Click the "+" symbol in the upper right corner of the page and select "create nw repository". Fill in the details as shown in the figure below and click "create repository".

Creating a repository on GitHub

Once created, we can push the local warehouse to the warehouse under your name in GitHub and connect to the warehouse on GitHub with the following command:

Please note: be sure to replace "user_name" and "Mytest" in the path with your GitHub username and directory name before running the following command!

Git remote add origin https://github.com/user\_name/Mytest.git>8, push files from the local warehouse to the GitHub warehouse

* one step is to push the contents of the local warehouse to the remote warehouse (GitHub) with the following command:

Git push origin master

Type the login name and password when prompted.

The following picture shows the process from step 5 to step 8

Pushing files in local repository to GitHub repository

The above pushes all the contents (files) in the Mytest directory to GitHub. For future projects or creating new warehouses, you can start directly from step 3. *, if you log in to your GitHub account and click on your Mytest repository, you will see these two files: README and sample.c have been uploaded and shown in the following image:

The above is all the contents of the article "how to install and use Git and GitHub on Ubuntu Linux". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report