World map

 

BM: Baca dalam Bahasa Melayu

World 4: Hello GitHub

Remotes and origin

You will learn: how to tell Git where your GitHub repo lives.

The problem

Your empty diary repo on GitHub has a long web address. Must you type it on every push?

Pick one answer.

Watch

git remote add saves the GitHub address as origin. git remote -v lists origin twice: once for fetch, once for push. Terminal output: $ git remote add origin https://github.com/you/diary.git $ git remote -v origin https://github.com/you/diary.git (fetch) origin https://github.com/you/diary.git (push)

A remote / origin: A copy of your project on the internet, for example on GitHub. is a contact in Git’s address book. git remote add origin <url> saves GitHub as origin. git remote -v lists your contacts.

Try it

Build the command that saves your GitHub address as origin.

Tap the pieces in the right order.

…

Try it

Now type it in your diary. Then check with git remote -v.

Predict

Is the name origin special to Git?

Pick one answer.

Check

Tap the line Git uses when you push.

~/diary $ git remote add origin https://github.com/you/diary.git~/diary $ git remote -v

0 of 1 found

You did it!

You can now connect your project to a repo on GitHub.

Go deeper (optional)

Typo in the address? git remote set-url origin <new-url> fixes it. git remote rename and git remote remove exist too. Removing a remote only deletes the contact. The repo on GitHub stays.

A remote with a typo in the address gets fixed with git remote set-url. Terminal output: $ git remote add origin https://github.com/you/diry.git $ git remote set-url origin https://github.com/you/diary.git $ git remote -v origin https://github.com/you/diary.git (fetch) origin https://github.com/you/diary.git (push)