Publish Code to Remote Repository

After setting up your SSH key and adding it to GitHub, you can push your code to a remote repo.

1. Create Local Repository

git init
git add <files>
git commit -m "Your commit message"

2. Check Remote URLs

git remote -v    # View configured remote repositories

3. Add Remote Repository

git remote add origin <remote-url>
  • origin → default name for the remote repo
  • <remote-url> → GitHub repository URL

Example:

git remote add origin https://github.com/alamgir-ahosain/git-test.git

alt text

4. Push Code to Remote

git push origin master
  • Pushes local master branch to remote origin

alt text

5. Set Upstream (Recommended)

git push -u origin master
  • Sets origin/master as the upstream branch
  • Allows future use of:
git push
git pull

alt text alt text

6. Upstream Remote (Optional – for forks)

git remote add upstream <remote-url>
  • Used to sync with the original repository

Summary

  • origin → your remote repo
  • upstream → original source repo
  • -u → link local branch with remote branch