Country or region and language

    Choose your country or region and your language.

    Suggested for you

      All countries and regions

        Choose your character

        It shows in the top bar and on your profile. Change it any time.

        What is Git and GitHub

        Learn what Git and GitHub are, record a local commit, and publish a support note. Check why saved changes and new commits don't reach GitHub until you push.

        A person practicing on a laptop in a quiet workspace

        Git is version control software that records versions of your files; GitHub is an online service that hosts Git projects and their history. If you're asking “what is Git and GitHub,” the essential difference is that a Git commit records work on your computer, while a push sends those commits to GitHub. You can use Git without GitHub, and committing doesn't automatically publish anything.

        Git and GitHub in plain English

        Git tracks changes inside a repository, which is a project's files together with their recorded history. Version control lets you inspect what changed and recover earlier work. Instead of keeping separate folders called “final” and “final-again,” you record meaningful versions in the same repository.

        GitHub hosts a remote copy of a repository: a copy outside your local project folder that you can access over a network. Git handles the history; GitHub provides a place to publish that history and collaborate around it. A Git repository doesn't have to be hosted on GitHub.

        In the exercise, you'll create a fictional support note, record its draft version locally, and publish it. Then you'll change the note to reviewed and check GitHub before and after pushing. That comparison makes the difference between recording and publishing visible.

        The path from editing to publishing

        Editing, staging, committing, and pushing are separate steps, and each step changes a different part of the workflow. Knowing those boundaries helps you diagnose why GitHub doesn't show your latest work.

        • Editing changes a file in your working directory, the project folder where you work.
        • Staging selects content for the next commit. The staging area holds that selection, not necessarily every saved change.
        • Committing records the staged content as a snapshot in the repository's local history.
        • Pushing sends local commits to a remote repository, such as the repository you create on GitHub.

        A branch is a movable name for a line of development. The exercise uses a branch named main. A remote is a named connection to another repository; origin is the conventional remote name used here, not a separate service.

        Use Git 2.28 or later with Bash on Linux, macOS, or Git Bash on Windows. You'll need Git installed, a GitHub account, and working authentication for Git command-line access. Signing in to the GitHub website doesn't by itself configure command-line authentication. For setup guidance, find GitHub Docs' “Set up Git” and “About authentication to GitHub” pages.

        Practice what this post teaches

        A small repository from start to finish

        The complete exercise below creates one text file and follows it from a local draft to a published revision. Run the commands in order in the same Bash session, pausing for the GitHub website steps written as comments.

        The fictional name and email label the exercise's commits. The configuration commands apply only to this repository because they don't use the global option. Commit identity doesn't sign you in to GitHub, and the example email isn't an authentication credential.

        If you'd like to practise the editing, staging, and committing workflow alongside this example, use The Work Gym's Git course.

        # Fictional exercise: publish a support note and then update it.
        # Target: notes.txt on GitHub contains exactly Status: reviewed
        # followed by a newline.
        # Starting state: Git 2.28+ and Bash; an unused support-notes directory;
        # no existing support-notes repository in your GitHub account;
        # working GitHub command-line authentication; no other contributors.
        # Initial file: notes.txt contains exactly Status: draft plus a newline.
        # Model: edit -> stage -> commit records locally; push publishes commits.
        
        mkdir support-notes
        cd support-notes
        git init -b main
        git config user.name "Practice Learner"
        git config user.email "[email protected]"
        printf 'Status: draft\n' > notes.txt
        git add notes.txt
        git commit -m "Record draft status"
        git log -1 --format=%s
        # Expected: Record draft status
        git show HEAD:notes.txt
        # Expected: Status: draft
        
        # On GitHub, create a repository named support-notes.
        # Leave it empty: don't add a README, license, or .gitignore.
        # Copy its repository URL using your configured authentication method.
        # At the prompt below, paste that URL, then press Enter.
        read -r -p "Paste your GitHub repository URL: " remote_url
        git remote add origin "$remote_url"
        git push -u origin main
        # Refresh the GitHub repository page and open notes.txt.
        # Expected GitHub file content: Status: draft
        
        # Variation: replace the content of notes.txt with the reviewed status.
        printf 'Status: reviewed\n' > notes.txt
        git diff -- notes.txt
        # Expected diff includes: -Status: draft and +Status: reviewed
        
        git add notes.txt
        git commit -m "Mark note reviewed"
        git show HEAD:notes.txt
        # Expected local content: Status: reviewed
        # Refresh notes.txt on GitHub before pushing.
        # Expected GitHub content is still: Status: draft
        
        git push
        # Refresh notes.txt on GitHub again.
        # Expected GitHub content: Status: reviewed
        
        git status --porcelain
        # Expected: no output, meaning no uncommitted local changes.
        

        The first command creates the project folder, and changing into that folder ensures the remaining commands affect the intended project. Git initialisation creates the repository and chooses main as its starting branch. The first add command selects the note's draft content; the first commit records that selection.

        The log check prints the latest commit's subject. The show check reads the note from the current commit, rather than from the editable file. HEAD identifies the current commit in this exercise. Git's commit identifiers and transfer messages vary, so compare the preserved subject and file content instead of expecting a particular identifier.

        Creating an empty GitHub repository matters. Adding a README on GitHub would introduce a separate initial history and make the first push more complicated. The remote command stores your repository URL under origin; adding that connection doesn't upload any files.

        Local commits before the push

        The reviewed-note variation proves that a local commit can be newer than the file displayed on GitHub. Follow the variation only after the first push has published the draft.

        First, the second file-writing command replaces the entire contents of notes.txt with the reviewed status. The diff command then compares the working file with the staging area. Its minus line identifies the removed draft text, and its plus line identifies the added reviewed text.

        Next, staging selects the reviewed content and committing records it locally. The following show command confirms that the current local commit contains the reviewed note. Refreshing the same file on GitHub before pushing should still show the draft. Both views are correct because they're reading different repository copies.

        The final push publishes the reviewed commit. The first push used the upstream option to connect local main with origin/main, Git's local reference for the remote branch. An upstream is the default branch connection used by commands such as a plain push, which is why the second push needs fewer arguments.

        Common mistakes and useful limits

        An unchanged GitHub file usually calls for checking the workflow boundary, not repeating every command. Identify whether you stopped after saving, staging, committing, or pushing.

        • A saved edit isn't staged automatically. If you edit again after staging, the staging area still holds the earlier selection until you stage the newer content.
        • An unknown-author error concerns commit identity. Check the repository's name and email configuration from the exercise.
        • An authentication error during publishing concerns access to GitHub. Changing the commit author's email won't fix authentication.
        • A rejection caused by existing remote commits needs investigation. Don't force-push to bypass it; stop and learn how to fetch and integrate the existing history.

        Never commit passwords, access tokens, or private workplace files. A later edit that removes a secret doesn't remove the secret from earlier commits. Use fictional material while you're learning, and check the repository's visibility before publishing.

        The exercise covers one person's local-to-remote workflow. It doesn't cover shared branches, pull requests, which are proposals to review and merge changes, or merge conflicts, which require reconciling incompatible edits. Keep those topics separate until you can explain why the reviewed note stayed local before the final push.

        Common questions

        Can I use Git without GitHub? Yes. Git can record and inspect project history entirely on your computer. GitHub is one option for hosting a remote repository, not a requirement for using Git.

        Does committing a file automatically update GitHub? No. A commit records staged content in your local repository. You need to push the commit to the connected GitHub repository before GitHub displays that version.

        How do I update a GitHub repository after changing a file? Inspect the edit, stage the intended content, commit it, and push to the connected remote branch. The exercise's first push sets an upstream connection, allowing its later push to use that connection without repeating the remote and branch arguments.

        Do I need to know programming before learning Git? No. You can learn Git with a plain text file, as the support-note exercise demonstrates. Focus first on the difference between your working file, staged content, local commits, and published commits.

        Practice what this post teaches

        Your Work Gym account

        Save your progress and pick up on another device. Your browser's progress comes with you.

        or

        You can keep practicing without an account.

        Help and feedback

        Ask a question, tell us what is not working, or share an idea. We reply by email.

        What is it about?

        We use it only to reply to you.