🎉 Special Offer !    Code: GET300OFF    Flat ₹300 OFF on every Java Course
Grab Deal 🚀

Push Local Changes to Remote Repository -


Introduction

  • git push command is used to upload local repository content to a remote repository (e.g., GitHub, GitLab, Bitbucket).
  • It transfers your committed changes from the current local branch to a branch on the remote repository.
  • It ensures that your team or remote server has the latest version of your code.

How to use git push ?

  1. Open the Git terminal (or command prompt) and navigate to the project folder where your Git repository is initialized.
  2. Make sure that :-
    • You have already committed your changes using:
      • git commit Command
    • You have added the remote repository using:
      • git remote add origin https://github.com/SmartProgrammingCoders/GitDemo.git Command
    • You have checked that local and remote branch name are same, if not same then change it using:
      • git branch -M main Command
  3. Now run the git push command:
    • Syntax : git push origin <branch-name>
    • Example : git push origin main
  4. The commands will show the following output:
    • Git Push Command

Different ways to use git push ?

  1. Basic Push to Remote Repository::
    • Push committed changes from your local branch to a remote repository.
    • Syntax :
      • git push origin <branch-name>
    • Example:
      • git push origin main
  2. Push and Set Upstream (Track Remote Branch):
    • Sets the remote branch as the default upstream for your local branch.
    • Syntax:
      • git push -u origin <branch-name>
    • Example:
      • git push -u origin main
    • Note : After this, you can simply run git push next time.
  3. Push All Branches:
    • Push all local branches to the remote repository.
    • Example:
      • git push --all origin
  4. Push Tags:
    • If you’ve created Git tags and want to push them:
    • Example:
      • git push origin --tags
  5. Force Push:
    • Used to overwrite remote history with local changes (⚠️ use with caution).
    • Example:
      • git push --force
      • git push origin main --force
  6. Push to a Different Remote:
    • If your remote is named something other than origin, specify it:
    • Syntax:
      • git push my-remote-name <branch-name>