Push to a Remote Repository: git push

Git Tips & Commands

After you have a remote repository set up, you upload (push) your files and revision history to it.

Push Your First Changes to a New Remote Repo

1. In your terminal (Terminal, Git Bash, or Windows Command Prompt), navigate to the folder for your Git repo.

2. If you just created a repo on the GitHub or Bitbucket website, you should see the commands you need to push your local repo to the remote repo you just made. To connect your local repo to the remote repo, enter a command such as this (which you should be able to copy and paste from the GitHub/Bitbucket website):

git remote add origin https://user@bitbucket.org/user/repo.git

Your address (after origin) will vary based on your host and repo name.

Full-Stack Web Development Certificate: Live & Hands-on, In NYC or Online, 0% Financing, 1-on-1 Mentoring, Free Retake, Job Prep. Named a Top Bootcamp by Forbes, Fortune, & Time Out. Noble Desktop. Learn More.

What Is "Origin"?

Origin is an alias to the remote repository. We say origin so we won't have to write out the URL of the remote repo every time in the future. While origin is the name most people use, you can name it something else.

You can read more about origin at git-tower.com/learn/git/glossary/origin  and tinyurl.com/git-origin

3. You're now ready to make your first push, by running the following command (which should also be on the GitHub/Bitbucket page if you still have it open):

git push -u origin master

Things to note:

  •  -u is short for --set-upstream and adds an upstream (tracking) reference so in the future, Git will remember where we want to push to and pull from. That will allow us to usegit pull orgit push without having to specify extra arguments.
  •  origin represents the URL you just set up in the previous command.
  • master is the name of the branch (which we'll talk more about later).

4. If this is the first time pushing to the remote server, you should be asked to login with your username and password.

If something went wrong adding the remote origin, you can remove it using the command git remote rm origin and try adding it again.

5. If you go back to the GitHub/Bitbucket website and reload the page you should now see a list of your files.

How You Typically Push Changes

1. If the tracking information has already been set (when you did your first push, or if you originally cloned the repo from a remote server) you can use a simpler push command. Run either of these commands:

  • git push
  • git push origin master (note the lack of-u option)

Where Is My Origin?

Don't remember what the current repo's origin is? Run the following command to see what origin is set to:

git remote -v

Go Beyond Git

We offer a full suite of coding courses for students of all levels. Learn through real-world projects from expert instructors. Check out our coding bootcamps and classes now:

How to Learn Git

Master Git with hands-on training. Git is a free, open-source version control system that allows developers to track the changes they make to code.

Yelp Facebook LinkedIn YouTube Twitter Instagram