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

What are the basic ways to use Git

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

Share

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

This article mainly introduces the basic use of Git, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Git is an open source distributed version control system for efficient and high-speed version management of projects ranging from very small to very large.

Install Git

To install git, execute the following command:

Sudo apt-get install git-core

After it has been downloaded, you have installed Git and are ready to use it.

Set up Git

After Git installation, whether from apt-get or source code, you need to copy your user name and email address to the gitconfig file. You can access the file ~ / .gitconfig.

After a new installation of Git, opening it will be completely blank:

Sudo vim / .gitconfig

You can also use the following command to add the information you need. Replace "user" with your user name and "user@example.com" with your email address.

Git config-global user.name "User" git config-global user.email user@example.com

And then you finish the setup. Now let's start Git.

Warehouse

Create a new directory, open it, and run the following command:

Git init you should know the basic Git command you should know the basic Git command

This command creates a new Git repository (repository). Your local warehouse consists of three "trees" maintained by Git.

The first is your working directory (Working Directory), which saves the actual files. The second is the index, which actually acts as a staging area, and the last one is HEAD, which points to your last commit submission and uses git clone / path/to/repository to check out your warehouse (from the warehouse you just created or the warehouse that already exists on the server).

Add files and submit

You can add changes with the following command:

Git add

This adds a new file to the staging area for submission. If you want to add each new file, type:

Git add-all

After adding a file, you can use the following command to check the status:

Git status you should know the basic Git command you should know the basic Git command

As you can see, there have been some changes but haven't been submitted yet. Now you need to submit these changes, using:

Git commit-m "submit information" basic Git commands you should know basic Git commands you should know

You can also do this (preferred):

Git commit-a

Then write down your submission information. Now your file has been submitted to HEAD, but it is not in your remote warehouse yet.

Push your changes

Your changes are in the HEAD of your local working copy. If you haven't cloned from an existing warehouse or want to connect your warehouse to a remote server, you need to add it first:

Git remote add origin

Now you can push the changes to the specified remote server. To send changes to the remote server, run:

Git push-u origin master branch

Branches are used to develop features, and branches are independent of each other. The main branch master is the "default" branch when you create a warehouse. Use another branch for development and merge it back to the main branch when it is complete.

Create a branch called "mybranch" and switch to it:

Git checkout-b mybranch basic Git commands you should know basic Git commands you should know

You can use this command to switch back to the main branch:

If you want to delete this branch, execute:

Git branch-d mybranch basic Git commands you should know basic Git commands you should know

Unless you push the branch to a remote server, the branch is not available to others, so just push it up:

Git push origin updates and merge

To update your local warehouse to the latest submission, run:

Git pull

Get and merge remote changes in your working directory. To merge other branches into your active branch (such as master), use:

Git merge

In both cases, git tries to auto-merge the changes automatically. Unfortunately, this is not always possible and can lead to conflict. You need to manually merge those conflicts by editing the files shown in git. After the changes, you need to mark them as merged with the following command:

Git add

Before merging changes, you can also use the following command to preview:

Git diffGit log

You can look at the warehouse history like this:

Git log

To view the log in the style of one line per submission, you can use:

Git log-pretty=oneline

Or maybe you want to see an ASCII art tree with all branches, with a tag and branch name:

Git log-graph-oneline-decorate-all

If you only want to see which files have been changed:

Git log-name-status

Thank you for reading this article carefully. I hope the article "what are the basic uses of Git" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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

Development

Wechat

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

12
Report