Frage

Everything is in the title...

I read this question: Viewing Unpushed Git Commits

But I don't understand why git status displays all unpushed commits in the master branch, but does not display anything in other branches.

Can someone explain it?

EDIT

Here is what commands and outputs I did/get:

aurelien@server:/home/repo/$ git branch
  new_feature
* master

aurelien@server:/home/repo/$ git checkout new_feature
Switched to branch 'new_feature'

aurelien@server:/home/repo/$ echo test > newfile.txt
aurelien@server:/home/repo/$ git add newfile.txt
aurelien@server:/home/repo/$ git commit -m "Test commit"
[new_feature 51c6a64] Test commit
1 file added
aurelien@server:/home/repo/$ git status
# On branch new_feature
nothing added to commit

Why doesn't my commit appear when using git status?

War es hilfreich?

Lösung

The reason is that your master branch actually has a remote branch, on origin/master that your branch has been set up to track.

What this means is that each time you do a commit to master, and then do a git status git will tell you which commits are different between your local branch and the remote branch.

When you create a new branch, there's no corresponding remote branch by default. You can see this by doing git branch -a. that will show you all the remote branches that are set up.

So there are two things at play:

1) You don't have a remote branch for your local branch 2) Your branch isn't set up to track changes from the remote branch

One simple way to make a remote branch and set up tracking for your local branch, is to push the local branch to a remote branch:

git checkout new_feature
git push -u origin new_feature

Normally, when you just push without the -u switch, no tracking will be set up, but your branch will still be pushed. But when you pass in the -u switch it will tell git that you also want to set your branch to track changes from the remote branch.

After you do this and then make changes and commit them, then do a git status you'll get the expected result of "Your branch is a head of origin/new_feature by 1 commit"

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top