Skip to content

Pushing changes to origin master

Abhik Pramanik edited this page Aug 3, 2011 · 11 revisions

Once you commit to your local repository, you will need to push it up to origin/master (e.g. trunk in SVN terms). This tutorial will cover a simple push where you are synced up with origin/master and a slightly more complicated one where origin/master has additional commits.

  1. Let's say we left off from the Committing changes tutorial:

    % git commit -m "Adding clean instructions to INSTALL"
    [master 8e89ada] Adding clean instructions to INSTALL
     1 files changed, 4 insertions(+), 0 deletions(-)
    % git status
    # On branch master
    # Your branch is ahead of 'origin/master' by 1 commit.
    #
    # Changed but not updated:
    #   (use "git add <file>..." to update what will be committed)
    #   (use "git checkout -- <file>..." to discard changes in working
    #   directory)
    #
    #  modified:   INSTALL
    #  modified:   README
    #
    no changes added to commit (use "git add" and/or "git commit -a")
    

Simple

  1. Now run git push origin master (subsequent pushes can omit the origin master arguments).

    % git push origin master
    Counting objects: 5, done.
    Delta compression using up to 2 threads.
    Compressing objects: 100% (3/3), done.
    Writing objects: 100% (3/3), 408 bytes, done.
    Total 3 (delta 0), reused 0 (delta 0)
    To git@github.com:abhikp/git-test.git
        e055ef5..8e89ada  master -> master
    

    You can confirm that you and origin are synced up by running git status again.

    % git status
    # On branch master
    # Changed but not updated:
    #   (use "git add <file>..." to update what will be committed)
    #   (use "git checkout -- <file>..." to discard changes in working
    #   directory)
    #
    #    modified:   INSTALL
    #    modified:   README
    #
    no changes added to commit (use "git add" and/or "git commit -a")
    

Remote has additional commits

  1. If your commit log (minus the last commit) doesn't match that of origin master it will complain when you run git push.

    % git push
    To git@github.com:abhikp/git-test.git
    ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to 'git@github.com:abhikp/git-test.git'
    To prevent you from losing history, non-fast-forward updates were rejected
    Merge the remote changes before pushing again.  See the 'Note about
    fast-forwards' section of 'git push --help' for details.
    
  2. You'll need to sync back up by pulling from origin master. We'll just run the commands here and leave the details to Pulling from a remote branch.

    % git stash
    Saved working directory and index state WIP on master: f35474c Adding clean instructions to INSTALL
    HEAD is now at f35474c Adding clean instructions to INSTALL
    % git pull --rebase
    remote: Counting objects: 4, done.
    remote: Compressing objects: 100% (2/2), done.
    remote: Total 3 (delta 0), reused 3 (delta 0)
    Unpacking objects: 100% (3/3), done.
    From github.com:abhikp/git-test
        e055ef5..99b1d17  master     -> origin/master
        First, rewinding head to replay your work on top of it...
        Applying: Adding clean instructions to INSTALL
    % git push
    Counting objects: 5, done.
    Delta compression using up to 2 threads.
    Compressing objects: 100% (3/3), done.
    Writing objects: 100% (3/3), 440 bytes, done.
    Total 3 (delta 0), reused 0 (delta 0)
    To git@github.com:abhikp/git-test.git
        99b1d17..94ae280  master -> master
    

Clone this wiki locally