Skip to content

Latest commit

 

History

History
53 lines (42 loc) · 1.6 KB

File metadata and controls

53 lines (42 loc) · 1.6 KB

Git Push Guide

Since you have already initialized the repository and committed your changes, here are the steps to push your code to a remote repository (like GitHub, GitLab, or Bitbucket).

Prerequisites

  • You need a repository URL from your Git provider (e.g., https://github.com/username/repo-name.git).

Steps

1. Check Existing Remotes

First, check if you already have a remote server linked:

git remote -v
  • If you see origin listed, skip to Step 3.
  • If it returns nothing, proceed to Step 2.

2. Add Remote Repository

Link your local repository to the remote one using the URL you copied:

git remote add origin <YOUR_REPOSITORY_URL>

Replace <YOUR_REPOSITORY_URL> with your actual link.

3. Ensure You Are on the Main Branch

It is common practice to name the default branch main. Rename your current branch to main just in case:

git branch -M main

4. Push Your Code

Push your commits to the origin remote on the main branch. The -u flag links your local branch to the remote one for future pushes.

git push -u origin main

Troubleshooting

"Remote origin already exists"

If you tried to add a remote but got this error, and you want to change it to a new URL:

git remote set-url origin <NEW_REPOSITORY_URL>

"Updates were rejected because the remote contains work that you do not have"

If the remote repository was created with a README or License file, you might need to pull those changes first:

git pull origin main --allow-unrelated-histories
# Then try pushing again
git push -u origin main