📜  git mainstages - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:30:55.699000             🧑  作者: Mango

Git Mainstages - Shell-Bash

Git is a powerful version control system that allows programmers to track changes to their code over time. One of the key features of Git is the ability to stage changes before committing them. In this tutorial, we will be covering the mainstages of Git - Shell-Bash.

1. Initial Setup

Before we start, we need to make sure that Git is installed on our system. To check if Git is installed, run the following command in your terminal:

git --version

If Git is not installed on your system, you can download it from the official website at https://git-scm.com/downloads.

Once Git is installed, we need to configure our name and email address. This information is used to identify who made the changes to a file. To set your name and email address, run the following commands in your terminal:

git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"
2. Create a Repository

To start tracking changes to our code, we need to create a Git repository. A Git repository is a folder that contains all the files for our project and a hidden .git folder that tracks changes to the files.

To create a new Git repository, navigate to the folder containing your project in your terminal and run the following command:

git init
3. Stage Changes

Once we have created a Git repository, we can start tracking changes to our files. To do this, we need to stage the changes before committing them.

To stage changes, we use the git add command. This command tells Git which changes to include in the next commit.

To stage all changes, run the following command:

git add .

To stage individual files, run the following command:

git add filename.txt
4. Commit Changes

After we have staged our changes, we can make a commit. A commit is a snapshot of our code at a specific point in time. Each commit has a unique identifier that allows us to track changes over time.

To make a commit, we use the git commit command. This command creates a new commit with the changes that we have staged.

To commit changes, run the following command:

git commit -m "Commit message"

The -m flag is used to add a message to the commit. This message should be a brief description of the changes that were made.

Conclusion

In this tutorial, we covered the mainstages of Git - Shell-Bash. We learned how to set up Git, create a repository, stage changes, and make a commit. These are the basic steps needed to start using Git for version control in your projects.