Get AI summaries of any video or article — Sign up free
Git Tutorial for Beginners: Command-Line Fundamentals thumbnail

Git Tutorial for Beginners: Command-Line Fundamentals

Corey Schafer·
5 min read

Based on Corey Schafer's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.

TL;DR

Git is distributed: every local repository contains the history from the last sync, reducing reliance on a central server.

Briefing

Git command-line fundamentals hinge on one practical advantage: distributed version control keeps a full copy of repository history on every developer’s machine, so work can continue even when the central server is unreachable. In contrast to centralized systems like SVN—where access depends on a single server and outages or corruption can be catastrophic—Git’s distributed model means each local repository contains the information from the last sync. If the remote repository fails, developers still have the changes they pulled earlier, effectively acting as backups.

After that conceptual setup, the tutorial walks through getting Git installed and ready for real use. Installation comes from g-s cm.com, followed by a quick verification using git --version. The next step is global configuration: setting user.name and user.email with git config --global user.name "..." and git config --global user.email "..." so commits are attributed correctly across teams. To reduce friction later, built-in help is highlighted via git help <command> or git <command> --help, which opens the manual pages for commands like config and add.

From there, the workflow splits into two common scenarios: starting a new project locally and cloning an existing project from a remote source. For a local project, the process begins with git init inside the project directory, which creates a .git directory containing repository metadata. Running git status shows untracked files, and the tutorial emphasizes ignoring machine- or personal-specific files by creating a .gitignore file (including examples like *.pyc). Files move through three states: the working directory, the staging area, and committed history. git add stages changes—either selectively or with git add -A—while git reset can unstage them. A commit is created with git commit -m "message", and git log provides the commit hash, author, and message.

For remote collaboration, the tutorial uses git clone <url> <destination> to copy an existing repository into a local folder. It then demonstrates how to inspect remotes with git remote -v and list branches with git branch -a. When changes are made, git diff shows what changed, git add stages, git commit records locally, and git push sends updates to the remote. Before pushing, git pull is recommended to fetch any upstream changes from other developers; the example shows git pull reporting “already up to date” when nothing new exists.

Branching is presented as the standard way to develop features without disrupting master. The tutorial creates a branch with git branch <name>, switches with git checkout <name>, commits changes on that branch, and pushes it to the remote using git push -u origin <branch>. After tests pass, the feature branch is merged back into master via git checkout master, git pull, git merge <branch>, and git push origin master. Once merged, the branch can be deleted locally with git branch -d <branch> and remotely with git push origin --delete <branch>. The result is a repeatable daily routine: commit locally, sync with git pull, push with git push, and merge through branches when ready.

Cornell Notes

Git’s core advantage is distributed version control: every developer’s local repository contains a full copy of the project history from the last sync, so work can continue even if the central remote is unavailable. The tutorial shows how to install Git, verify it with git --version, and set global identity using git config --global user.name and git config --global user.email. It then demonstrates the local workflow: git init, git status, using .gitignore to exclude unwanted files, staging with git add, un-staging with git reset, committing with git commit -m, and reviewing history with git log. For collaboration, it covers git clone, git remote -v, git pull, git push, and a branching workflow that merges feature branches back into master and then deletes them.

Why does Git’s distributed model matter compared with centralized systems like SVN?

In centralized version control, everything depends on one central server: developers check out from that location, make changes, and push them back. If the server is offline or corrupted, developers can’t reliably access the full repository history or updates. In Git’s distributed model, each developer has a local repository containing the information from the last time it synced with the remote. That means even without access to the remote, developers can still view changes since the repository was created, and in worst-case scenarios the local copies act like backups.

What are the three states Git uses, and how do commands move files between them?

Git tracks changes across the working directory, the staging area, and committed history. git status shows what’s currently in the working directory (e.g., untracked or modified). git add moves selected changes into the staging area, where they’re ready to be committed. git commit -m records the staged snapshot into the repository history. git reset can move files out of the staging area back to the working directory (or unstage everything if run without specific paths).

How does .gitignore prevent accidental commits of machine-specific or personal files?

After git init, git status may show untracked files that shouldn’t be shared. Creating a .gitignore file lets Git ignore patterns such as *.pyc (to exclude Python bytecode) or specific files like a project file created for local preferences. Once the patterns are saved, rerunning git status should stop listing ignored files as untracked, while still showing the files that matter (like the .gitignore itself and other real source files).

What’s the typical sequence for pushing changes to a remote repository?

After editing code, git diff shows what changed. git status confirms the modified files. Then git add -A (or targeted git add) stages the changes, and git commit -m "message" records them locally. Before pushing, git pull fetches any remote updates made since the last sync. Finally, git push origin master sends the committed changes to the remote branch (origin is the remote name; master is the target branch).

How does the feature-branch workflow protect master, and what commands complete the merge?

Instead of working directly on master, a feature branch is created with git branch <branch> and switched to with git checkout <branch>. Changes are committed on that branch, then pushed with git push -u origin <branch>. When ready, the workflow returns to master (git checkout master), pulls remote updates (git pull), merges the feature branch (git merge <branch>), and pushes the updated master (git push origin master). Afterward, the branch is deleted locally with git branch -d <branch> and remotely with git push origin --delete <branch>.

Review Questions

  1. When would git pull be necessary before git push, and what problem does it prevent?
  2. Describe the difference between git add and git commit in terms of where changes live.
  3. What is the purpose of git branch -d versus git push origin --delete for feature branches?

Key Points

  1. 1

    Git is distributed: every local repository contains the history from the last sync, reducing reliance on a central server.

  2. 2

    Install Git from g-s cm.com, verify with git --version, then set identity using git config --global user.name and git config --global user.email.

  3. 3

    Initialize a local repository with git init, then use git status to see untracked and modified files.

  4. 4

    Use .gitignore to exclude files you don’t want committed (for example, patterns like *.pyc or local preference files).

  5. 5

    Stage changes with git add (git add -A for all) and unstage with git reset when needed.

  6. 6

    Commit staged changes with git commit -m "message" and review history with git log to see commit hashes and messages.

  7. 7

    Collaborate by cloning with git clone, syncing with git pull, sending updates with git push, and using feature branches merged back into master.

Highlights

Git’s distributed model means a remote outage doesn’t stop progress: local repositories retain the history from the last sync.
The staging area exists so commits can be curated—git add selects what goes into the next commit, not everything changed in the working directory.
A safe daily workflow uses branches: develop on a feature branch, push it, merge into master after pulling, then delete the branch locally and remotely.

Topics

  • Distributed Version Control
  • Git Installation
  • Local Repository Workflow
  • Remote Collaboration
  • Branching and Merging