Skip to content

Git fundamentals

↑

CLI examples labeled Bash work in Git Bash on Windows 10 and Windows 11, or Bash on Linux, with Git installed. Bash variable assignments such as DEFAULT_BRANCH=main are shell syntax; use Git Bash for these examples rather than pasting them into PowerShell or Command Prompt.

Git is a distributed version-control system. A repository contains a graph of commits, and each commit points to a snapshot of tracked content plus its parent history. A branch is a movable name for a commit; it is not a duplicate of every file. A remote such as origin is a named place to exchange commits, typically on GitHub or GitLab.

  1. Working tree: the files you are editing. Untracked files have not yet been added to Git.
  2. Staging area (index): the exact version of each selected file you intend to include in the next commit.
  3. Commit history: saved snapshots, identified by commit hashes. A commit is local until pushed to a remote.

Think of Save in your editor, Commit in Git and Push to a remote as three different actions. A green IDE indicator doesn’t mean teammates can see your code.

  1. Choose File → Clone Repository and select a GitHub repository, or choose the URL tab.
  2. Select the local folder and click Clone.
  3. Check Current Branch, then use Fetch origin to see remote updates.
  4. Use the Changes tab to see pending edits; History displays commits.

GitHub Desktop is supported on Windows and macOS. GitLab-hosted repositories may be cloned by URL, but GitHub-specific pull-request features are not interchangeable with GitLab merge requests.

Fetch downloads remote references and objects without changing your checked-out files. Pull fetches and then integrates remote work; with --ff-only, it refuses to create an unexpected merge commit. Push sends your local commits to the remote if the server accepts them. Before a push, review both the diff and the destination branch.

Select Fetch origin to check remote changes. If Desktop offers Pull origin, review your local changes before pulling. On your feature branch, Push origin publishes its commits. Desktop shows whether the current branch has unpushed work.

If you edited a file but have not staged it, the change belongs to your working tree. If you committed it but did not push, it belongs to your local repository. If you pushed it to a feature branch, teammates can inspect it, but it has not become part of protected main.

Related reading: branches, daily workflow and official Git reference.

Branch naming: main is an example. Use master or your repository’s actual default branch where applicable. See Git terminology.