Git and SSH: Two-Week Learning Experience
This article explains what a typical two-week learning curve for Git and SSH looks like, from setting up a local repository to pushing it to GitHub. You will learn the essential commands, common pitfalls, and the background knowledge needed to work confidently with these tools. By the end, you should understand the workflow and be able to apply it to your own projects.
Background: Why Git and SSH Matter
Git is a distributed version control system that tracks changes in source code during software development. It allows multiple people to work on the same project without overwriting each other’s work. SSH (Secure Shell) is a cryptographic network protocol used for secure data communication, remote command-line login, and other secure network services between two computers. When you push your local Git repository to GitHub, SSH provides an encrypted channel, so your credentials and data are safe.
How Git and SSH Work Together
Git stores your project’s history in a hidden folder called .git. When you make a commit, Git takes a snapshot of your changes. To share those changes with GitHub, you need a remote repository. SSH is used to authenticate your computer to GitHub without typing your password every time. You generate a public and private key pair on your machine, add the public key to your GitHub account, and then Git uses SSH to securely connect to GitHub’s servers.
First Steps: Local Repository and Commits
In the first few days, you typically learn to initialize a repository and make commits. The basic workflow is:
- Create a project folder and navigate into it.
- Run
git initto start tracking changes. - Add files with
git add .to stage them. - Commit with
git commit -m "initial commit". - Check status with
git statusand history withgit log.
This is the foundation. You also learn about branches, which allow you to work on features separately, and merging, which integrates those branches back.
Setting Up SSH Keys
To connect to GitHub via SSH, you need to generate a key pair. On most systems, you can do this with:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
This creates a public key (id_rsa.pub) and a private key (id_rsa). You then copy the public key to your GitHub account under Settings → SSH and GPG keys. The private key stays on your computer and should never be shared. After that, you can test the connection with ssh -T git@github.com.
Pushing to GitHub
Once your SSH key is set up, you can add a remote and push your local commits. The commands are:
- Create a new repository on GitHub (without README, to avoid conflicts).
- Add the remote:
git remote add origin git@github.com:username/repo.git - Push:
git push -u origin main
The -u flag sets the upstream, so future pushes can be just git push. You also learn to pull changes with git pull and clone existing repos with git clone.
Common Problems and How to Solve Them
Beginners often run into a few classic issues:
- Permission denied (publickey) – This usually means your SSH key is not added to the agent or GitHub. Run
eval "$(ssh-agent -s)"and thenssh-add ~/.ssh/id_rsa. - Merge conflicts – When two people change the same line, Git can’t merge automatically. You must manually edit the file to resolve the conflict, then commit.
- Accidentally committing to main – You can create a new branch and reset main with
git reset --hard HEAD~1(use with caution). - Wrong remote URL – Check with
git remote -vand update withgit remote set-url origin ....
Differences Between HTTPS and SSH
You might wonder why not just use HTTPS. With HTTPS, you can use a personal access token instead of a password, but you have to enter it each time unless you configure a credential helper. SSH is more secure because it uses key pairs, and once set up, you don’t need to enter anything. For most developers, SSH is the preferred method for frequent pushes. However, HTTPS can be simpler for one-off clones, especially on shared computers where you don’t want to leave private keys.
Costs and Safety Considerations
Both Git and SSH are free and open-source. GitHub offers free public repositories and limited private ones. The main cost is time – learning the commands and troubleshooting. Safety-wise, never share your private key or commit it to a repository. Use a passphrase when generating your key to protect it if your computer is stolen. Also, be careful with commands like git push --force, which can overwrite remote history.
Alternatives and Next Steps
If SSH seems too complex, you can use GitHub Desktop or other GUI clients that handle authentication for you. But learning the command line gives you more control and is essential for server work. After two weeks, you should be comfortable with the basic workflow. To go further, learn about rebasing, stash, and submodules. Practice by contributing to open-source projects, which will expose you to real-world collaboration.
Frequently Asked Questions
Do I need SSH for Git?
No, you can use HTTPS with a personal access token. SSH is just another authentication method that many find more convenient after the initial setup.
What if I forget my SSH passphrase?
You cannot recover it. You would need to generate a new key pair and update GitHub with the new public key.
How do I change the remote from HTTPS to SSH?
Run git remote set-url origin git@github.com:username/repo.git to switch.
Why does my push say “failed to push some refs”?
This usually means the remote has commits you don’t have locally. Pull first with git pull, resolve any conflicts, then push again.
Can I use the same SSH key for multiple GitHub accounts?
Technically yes, but it’s not recommended because it’s harder to manage. Better to create separate keys and use an SSH config file to associate each key with a specific host.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.