Pushing to GitHub¶
Your repo exists only on your laptop. Now you'll put it on GitHub.
Create an empty repo on GitHub¶
- Go to https://github.com/new.
- Repository name:
my-robot. - Leave Add a README, .gitignore and license turned off. Your local repo already has a history, and GitHub's repo must start empty.
- Click Create repository.
Connect and push¶
GitHub shows you the commands. From inside ~/my-robot:
git remote add origin <url>tells your repo where its GitHub copy lives.originis the standard name for it.git push -u origin mainuploads yourmainbranch. The-uremembers the connection, so afterwards plaingit pushis enough.
Refresh the GitHub page: your files and commit history are there.
The shortcut
gh can create the GitHub repo and push in one step:
The everyday loop¶
From now on, after you commit, push:
Getting a repo onto another computer: clone¶
To download a repo from GitHub, clone it. Try it with your own repo in a different folder:
cd ~
git clone https://github.com/<your-username>/my-robot.git my-robot-copy
cd my-robot-copy
git log --oneline
The clone has the full history and is already connected to origin.
Getting new changes: pull¶
Change something on GitHub's website: open README.md, click the pencil icon, edit, and Commit changes. Then back in your original folder:
git pull downloads new commits from GitHub and merges them into your branch.
Pull before you start working
Make git pull the first thing you do when you sit down to work on a shared repo.
Clean up the copy when you're done: