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.
The three local states
Section titled “The three local states”- Working tree: the files you are editing. Untracked files have not yet been added to Git.
- Staging area (index): the exact version of each selected file you intend to include in the next commit.
- 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.
Clone or open a repository
Section titled “Clone or open a repository”- Choose File → Clone Repository and select a GitHub repository, or choose the URL tab.
- Select the local folder and click Clone.
- Check Current Branch, then use Fetch origin to see remote updates.
- 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.
git clone https://github.com/OWNER/REPOSITORY.gitcd REPOSITORYgit status --short --branchgit remote -vgit log -5 --oneline --decorateThe URL and folder above are placeholders. For a private repository, use the authentication method allowed by your organization; do not paste tokens into shell history.
Understand fetching, pulling and pushing
Section titled “Understand fetching, pulling and pushing”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.
git statusgit fetch origingit log --oneline --decorate -5git pull --ff-onlygit pushRun these only after confirming which branch you are on. git pull --ff-only can fail when local and remote histories diverge; investigate rather than forcing a push.
Check your understanding
Section titled “Check your understanding”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:
mainis an example. Usemasteror your repository’s actual default branch where applicable. See Git terminology.
