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.


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.



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.




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
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"

Push and open a pull request
git push -u origin docs/update-readmeOn 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.

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-onlyIf a fast-forward is impossible, inspect the local and remote changes before choosing how to integrate them.

Reader Comments 0
Sign in with email or Google to join the discussion.