CodeBlanks Logo Icon CodeBlanks

Push to GitHub

Add a remote and push local commits to GitHub with the first push.

Add a GitHub Remote Repository

To connect your local repository to a repository on GitHub, use the git remote add command. The remote repository is commonly named origin.

git remote add origin https://github.com/user/project.git

This registers the remote repository address in your local repository; it does not upload files to GitHub yet.

Practice Register the GitHub Remote Address

Add the GitHub repository sample-user/web-project to the local repository with the name origin. Then print a message confirming that the remote has been registered.

Starter code

terminal
print("Uzak depo hazırlanıyor")

Sample solution

terminal
git remote add origin https://github.com/ornek-kullanici/web-proje.git
print("GitHub adresi eklendi")

Expected output

Uzak depo hazırlanıyor
GitHub adresi eklendi

Practice Complete the First Push

Push the local main branch to the origin remote repository. Set up upstream tracking during the first push and print a completion message.

Starter code

terminal
print("GitHub gönderimi başlıyor")

Sample solution

terminal
git push -u origin main
print("İlk gönderim tamamlandı")

Expected output

GitHub gönderimi başlıyor
İlk gönderim tamamlandı

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which command registers a GitHub address in a local repository?

  • git remote add origin address Correct answer
  • git branch add origin address
  • git commit origin address
  • git status origin address

Explanation: Correct. The git remote add origin command registers the remote repository in your local project.

2 Set Upstream on the First Push

Question
git push -u origin ____
Answer
git push -u origin main

Explanation: The -u option sets up upstream tracking between the local branch and the remote branch during the push.

3 GitHub Publishing Concepts

Term Meaning
git remote add Registers a remote repository
git push Uploads commits
-u Sets upstream tracking
origin Common remote name

All lessons in Beginner