Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git - Your branch is ahead of 'origin/master' by 1 commit

Tags:

git

commit

push

People also ask

What does your branch is ahead of origin master by 1 commit mean?

The message you're seeing (your branch is ahead by 1 commit) means that your local repository has one commit that hasn't been pushed yet. In other words: add and commit are local operations, push , pull and fetch are operations that interact with a remote.

What is commit ahead in git?

It's ahead of origin/master , which is a remote tracking branch that records the status of the remote repository from your last push , pull , or fetch . It's telling you exactly what you did; you got ahead of the remote and it's reminding you to push.


You cannot push anything that hasn't been committed yet. The order of operations is:

  1. Make your change.
  2. git add - this stages your changes for committing
  3. git commit - this commits your staged changes locally
  4. git push - this pushes your committed changes to a remote

If you push without committing, nothing gets pushed. If you commit without adding, nothing gets committed. If you add without committing, nothing at all happens, git merely remembers that the changes you added should be considered for the following commit.

The message you're seeing (your branch is ahead by 1 commit) means that your local repository has one commit that hasn't been pushed yet.

In other words: add and commit are local operations, push, pull and fetch are operations that interact with a remote.

Since there seems to be an official source control workflow in place where you work, you should ask internally how this should be handled.


git reset HEAD^ --soft (Save your changes, back to last commit)

git reset HEAD^ --hard (Discard changes, back to last commit)


If you just want to throw away the changes and revert to the last commit (the one you wanted to share):

git reset --hard HEAD~

You may want to check to make absolutely sure you want this (git log), because you'll loose all changes.

A safer alternative is to run

git reset --soft HEAD~ # reset to the last commit
git stash              # stash all the changes in the working tree 
git push               # push changes 
git stash pop          # get your changes back 

I resolved this by just running a simple:

git pull

Nothing more. Now it's showing:

# On branch master
nothing to commit, working directory clean

git reset HEAD^

then the modified files should show up.

You could move the modified files into a new branch

use,

git checkout -b newbranch

git checkout commit -m "files modified"

git push origin newbranch

git checkout master

then you should be on a clean branch, and your changes should be stored in newbranch. You could later just merge this change into the master branch


git reset HEAD <file1> <file2> ...

remove the specified files from the next commit