KevsRobots Learning Platform
By , Minute
So far your repository only exists on your computer. A remote is a copy of it somewhere else, usually on GitHub. Having one means:
You push your commits up to the remote, and pull new commits down from it.
flowchart LR
L["Your computer<br/>(local repository)"] -- "git push" --> G["GitHub<br/>(remote: origin)"]
G -- "git pull" --> L
G -- "git clone" --> P["Raspberry Pi<br/>(another copy)"]
pico-bot, and choose Public or Private.GitHub shows you a page with the address of your new repository. It looks like this:
https://github.com/your-username/pico-bot.git
Back in your pico-bot folder, tell Git about the remote. By convention, the main remote is called origin:
git remote add origin https://github.com/your-username/pico-bot.git
Check it worked:
git remote -v
origin https://github.com/your-username/pico-bot.git (fetch)
origin https://github.com/your-username/pico-bot.git (push)
GitHub doesn’t accept your normal password from the command line. You need a safer way to sign in. Pick one:
brew install gh on a Mac, or follow the instructions on the website for Linux and Raspberry Pi OS), then run gh auth login. Choose GitHub.com, then HTTPS, and say Yes when it asks to authenticate Git with your GitHub credentials.[email protected]: instead of https://.You only need to do this once per computer.
Now send your commits to GitHub:
git push -u origin main
Enumerating objects: 18, done.
Counting objects: 100% (18/18), done.
Writing objects: 100% (18/18), 2.10 KiB | 2.10 MiB/s, done.
To https://github.com/your-username/pico-bot.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.
-u (short for --set-upstream) links your local main to main on origin. You only need it the first time. After that, just run:
git push
Refresh your repository page on GitHub. Your files are there, and if you click commits you’ll see your whole history, every message you’ve written.
Pushing a new branch works the same way: git push -u origin obstacle-avoidance.
To get a copy of a repository onto another computer, such as your Raspberry Pi, use git clone:
git clone https://github.com/your-username/pico-bot.git
cd pico-bot
This downloads the whole repository, every commit and branch, into a new pico-bot folder, and sets up origin automatically. It works for anyone’s public repository, so it’s also how you download other people’s projects:
git clone https://github.com/kevinmcaleer/smars.git
pico-bot repository on GitHub and push your local one to it.README.md, commit it, and git push. Refresh GitHub to see it.git clone.git status after pushing. What does it say about origin/main?remote: Support for password authentication was removedgh auth login, or SSH, as described above.Why: GitHub stopped accepting account passwords for Git in 2021, for security.
error: failed to push some refs ... Updates were rejected because the remote contains work that you do not have locallygit pull first, then git push (see the next module).Why: Someone (perhaps you, on GitHub’s website) has pushed commits you don’t have. Git won’t let you overwrite them.
error: src refspec main does not match anygit branch. If it’s called master, push with git push -u origin master, or rename it with git branch -m main.Why: You can only push a branch that exists and has commits.
error: remote origin already existsgit remote set-url origin <new-url>.origin.Quick quiz 1 of 3
What is origin?
origin is just a nickname for the remote’s address, set by git remote add or git clone.Quick quiz 2 of 3
Why use -u the first time you run git push -u origin main?
-u, Git remembers where main should push to and pull from.Quick quiz 3 of 3
Which command downloads a full copy of a repository from GitHub?
git clone copies the whole repository, history and all, and sets up origin for you.
You can use the arrows ← → on your keyboard to navigate between lessons.
Comments