Chuck's Academy

Git Branching and Merging

Initial Setup and Basic Workflow

Initial Git Configuration

Before you start using Git, it is important to set up your identity so that your commits have the correct information. These settings are done once on your machine.

Configuring Your Identity

You can set your name and email using the following commands:

bash

These settings are stored in your Git configuration file and will be applied to all the repositories on your system.

Verifying the Configuration

You can verify your configuration with:

bash

This will show a complete list of your current settings.

Basic Git Workflow

Git follows a common workflow that includes creating files, tracking these files, staging changes, and committing these changes to the project's history.

Initializing a Repository

To start using Git in an existing project or a new one, initialize a repository:

bash

This creates a .git subdirectory that contains all the necessary files for the repository.

Repository Status

You can check the status of your repository at any time using:

bash

This command shows the files that are modified, those that are being tracked, and those that are not yet tracked by Git.

Adding Files to Git’s Staging Area

To start tracking a file, use:

bash

If you want to add all new and modified files, you can use:

bash

Making a Commit

Once you have added your files to the staging area, you can make a commit:

bash

The message should clearly describe what changes you have made.

mobile-image desktop-image

Viewing Commit History

You can see the history of all commits with:

bash

This command lists all the commits along with important details such as the commit hash, author, date, and the commit message.

Ignoring Files

Sometimes you will not want certain files to be tracked by Git. You can specify these files in a file called .gitignore. Example of a .gitignore file:

Cloning a Repository

If there is an existing repository that you want to contribute to or obtain a copy of, use:

bash

This creates a copy of the repository on your local machine.

Pushing Changes to a Remote Repository

Once you have made commits in your local repository, you can push these changes to a remote repository using:

bash

This command uploads your commits to the main branch of the remote repository called origin.

mobile-image desktop-image

Summary of Basic Workflow

  1. Make changes to files in your working directory.
  2. Add changes to the staging area using git add.
  3. Commit these changes with git commit.
  4. Push your changes to the remote repository with git push.

This concludes an overview of initial setup and basic workflow in Git. In the next chapter, we will explore the basics of branching in Git.


Ask me anything