Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

Git and GitHub for Beginners: Clone, Commit, Push, and Pull

Learn the difference between Git and GitHub and follow a Linux workflow for cloning, reviewing changes, committing, and opening a pull request.

Table of Contents

Git tracks changes in a local repository. GitHub hosts shared repositories and gives collaborators a place to review changes. A git commit records a change locally. A git push sends commits to a remote repository you can write to.

Git and GitHub - Using Git the right way to maximize your work Picture 1

Git and GitHub - Using Git the right way to maximize your work Picture 2

Set up Git on Linux

Install Git with your distribution's package manager, such as sudo apt install git on Debian or Ubuntu. Check that it runs with git --version, then set the name and email attached to your commits. Use the GitHub-provided no-reply address if you want to keep your personal email private.

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Connect to GitHub over SSH

You can clone a public repository over HTTPS without signing in. For SSH access to your own repository, follow the GitHub SSH guide. Check whether a key already exists before creating another, and give a new key a passphrase. The older screenshots below illustrate the flow, so match commands and settings to your current setup.

Git and GitHub - Using Git the right way to maximize your work Picture 3

Git and GitHub - Using Git the right way to maximize your work Picture 4

Git and GitHub - Using Git the right way to maximize your work Picture 5

Copy only the public key, whose filename ends in .pub, to GitHub SSH and GPG keys. Keep the private key on your device. Test with ssh -T git@github.com. If prompted about a first connection, verify the host fingerprint against GitHub's published fingerprints.

Git and GitHub - Using Git the right way to maximize your work Picture 6

Git and GitHub - Using Git the right way to maximize your work Picture 7

Git and GitHub - Using Git the right way to maximize your work Picture 8

Git and GitHub - Using Git the right way to maximize your work Picture 9

Clone a repository and make a branch

Copy the clone URL from the repository's Code menu. Use a repository you can contribute to, or a fork when the project uses that workflow. The commands below use a sample repository named project.

git clone git@github.com:OWNER/project.git
cd project
git switch -c docs/update-readme

Git and GitHub - Using Git the right way to maximize your work Picture 10

Stage and commit the change

Edit README.md, then inspect exactly what you will commit. Staging a named file reduces the chance of adding unrelated files or local secrets.

git status
git diff
git add README.md
git diff --staged
git commit -m "Clarify installation instructions"

Git and GitHub - Using Git the right way to maximize your work Picture 11

Git and GitHub - Using Git the right way to maximize your work Picture 12

Push and open a pull request

git push -u origin docs/update-readme

On GitHub, open a pull request from your branch into the repository's default branch. Include what you changed and how you checked it. The -u option records the upstream for future pushes from this branch.

Git and GitHub - Using Git the right way to maximize your work Picture 13

Pull updates for your next change

After the changes are merged, switch to the repository's default branch and update it. Replace main if your repository uses another name. Commit or set aside unfinished work before switching.

git switch main
git pull --ff-only

If a fast-forward is impossible, inspect the local and remote changes before choosing how to integrate them.

Git and GitHub - Using Git the right way to maximize your work Picture 14

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.