Push to remote

Push to remote repository

Now that we have a remote repository setup, let's see how we can push further modifications from local on to the origin.

Make a new commit

Let us make a small modification to the second file add it to the staging area and commit it to the local repo using the below command:

git commit -am "second file modified"
[master a0d9ab9] second file modified
 1 file changed, 1 insertion(+), 1 deletion(-)

Check the status and log

git status
On branch master

Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
git log --oneline
a0d9ab9 (HEAD -> master) second file modified
c7d349f (origin/master) hello modified again
4d7bd7f hello modified
299930d second file added
b1e291c initial contentb

We can see that we are one commit ahead of our origin since we have not yet pushed it!

Make another new commit

Let us make another new comment just to get to know the process better

Make a small modification to the same file and commit it using the below commands:

 git commit -am "second file modified again"
git status

On branch master

Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
git log --oneline

f488044 (HEAD -> master) second file modified again
a0d9ab9 second file modified
c7d349f (origin/master) hello modified again
4d7bd7f hello modified
299930d second file added
b1e291c initial content

This time we see that our local repo is ahead of the origin by 2 commits!

Push the commits

Now that we have made commits and we are ready to push the code or contents on to the origin, let us issue the below shown command:

git push
git status

On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
git log --oneline

f488044 (HEAD -> master, origin/master) second file modified again
a0d9ab9 second file modified
c7d349f hello modified again
4d7bd7f hello modified
299930d second file added
b1e291c initial content

Our local repo and origin are in sync with each other now.

Notice that we used only git push without mentioning anything else. This was possible because we had used the -u and set the origin as the default previously!

Last updated