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

8.0K    Asked by AvaBlack in Devops , Asked on Jun 8, 2021

I am new to git and working on it.

I added some files in git :

git add 
git add

then I wanted to push that for review, but mistakenly I did

git commit

so the files which I have changed don't go for reviews.

Now if I enter the command :

git status

Getting massage:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)

I want to revert that commit and I want to push those files for review rather than commit. Can anyone let me know how I can do that?

Answered by Carol Bower

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

Make your change.

git add - this stages the changes in the file for committing

git commit - this will commit your staged file locally and now be tracked by git.

git push - this will push your committed changes in a file to a remote repo

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 are seeing (your branch is ahead by one commit) means your native 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 a place where you work, you should ask internally how this should be handled.

Note :

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



Your Answer

Answer (1)

This message indicates that your local branch has one commit that hasn't been pushed to the remote repository's master branch (origin/master). To sync your changes with the remote repository, you can simply push your local commits to the remote master branch.


Here's how you can do it using Git:

  git push origin master

This command pushes your local commits from the master branch to the remote repository (origin) and updates the origin/master reference to match your local master branch.

After executing the push command, you should see a message indicating that the push was successful, and your local and remote branches should be in sync.

If you encounter any errors during the push, such as conflicts or authentication issues, you may need to resolve them before successfully pushing your changes.


6 Months

Interviews

Parent Categories