Skip to main content

Git Basics

Getting a Git Repository

You typically obtain a Git repository in one of two ways: You can take a local directory th...

Recording Changes to the Repository

At this point, you should have a bona fide Git repository on your local machine, and a checkout o...

Checking the Status of Your Files

The main tool you use to determine which files are in which state is the git status command. If y...

Ignoring Files

Often, you’ll have a class of files that you don’t want Git to automatically add or even show you...

Viewing Your Staged and Unstaged Changes

If the git status command is too vague for you — you want to know exactly what you changed, not j...

Committing Your Changes

Now that your staging area is set up the way you want it, you can commit your changes. Remember t...

Skipping the Staging Area

Although it can be amazingly useful for crafting commits exactly how you want them, the staging a...

Removing Files

To remove a file from Git, you have to remove it from your tracked files (more accurately, remove...

Moving Files

Unlike many other VCS systems, Git doesn’t explicitly track file movement. If you rename a file i...

Viewing the Commit History

After you have created several commits, or if you have cloned a repository with an existing commi...

Limiting Log Output

In addition to output-formatting options, git log takes a number of useful limiting options; that...

Undoing Things

At any stage, you may want to undo something. Here, we’ll review a few basic tools for undoing ch...

Unstaging a Staged File

The next two sections demonstrate how to work with your staging area and working directory change...

Unmodifying a Modified File

What if you realize that you don’t want to keep your changes to the CONTRIBUTING.md file? How can...

Working with Remotes

To be able to collaborate on any Git project, you need to know how to manage your remote reposito...

Showing Your Remotes

To see which remote servers you have configured, you can run the git remote command. It lists the...

Adding Remote Repositories

We’ve mentioned and given some demonstrations of how the git clone command implicitly adds the or...

Fetching and Pulling from Your Remotes

As you just saw, to get data from your remote projects, you can run: $ git fetch <remote&...

Pushing to Your Remotes

When you have your project at a point that you want to share, you have to push it upstream. The c...

Inspecting a Remote

If you want to see more information about a particular remote, you can use the git remote show &l...

Renaming and Removing Remotes

You can run git remote rename to change a remote’s shortname. For instance, if you want to rename...