1

so I am on a branch "somebranch," and I go back to master by git checkout master. I get the message "On Branch Master Your branch is up-to-date with 'origin/master'. Nothing to commit, working directory clean." This is the same message that comes up when I do a git status.

But then I do git pull, it pulls two changes to master. I checked git log and it seemed there was a new commit to master 3 minutes ago. Is there a lag with git status? I just did a git status and it again says I am up-to-date. I tried another pull right after and it pulled a new branch but no change to master - this I can understand, as git status probably only checks whether my current branch is up to date. But can someone explain how git status works and why there appears to be a lag?

Question 2: my git workflow at the moment is this:

  1. git checkout master
  2. git pull (so I am on the latest version)
    • now I want to work on some issue on a new branch
  3. git checkout -b newIssue
    • work on the issue, solve it
  4. git add .
  5. git commit -m "some msg"

at this point I would push, code review, and merge. I've had to do a rebase because 'origin/master' had advanced past me. How can I keep my branch newIssue up to date with master so I can just merge? How can I git pull from origin/master into newIssue?

Julien Chien
  • 2,052
  • 4
  • 16
  • 32

3 Answers3

1

The way you keep you newIssue branch up-to-date with respect to the upstream master is by rebasing it on master, as you already do. You can:

git checkout master
git pull
git checkout newIssue
git rebase master
...continue working...

Or you can:

git remote update
git rebase origin/master
...continue working...

Both will get you to the same place (but in the second case, your local master branch would still be behind origin/master until you do a git pull on that branch).

There may obviously be conflicts as part of the rebase if someone is modifying the same files you're working on, but rebasing regularly helps to minimize the size of these changes.

larsks
  • 277,717
  • 41
  • 399
  • 399
1

Regarding your first question, git status only looks at your own repository, not any remote repositories.

In general, to look at a remote repository, you have to copy anything new in it to your own repository first. The command that does this is git fetch (or you can use git remote update to do the same thing).

There is also git remote show origin, which consults the remote and compares your local idea of "where their branches are" with what they tell you. This may be what you were thinking you were getting with git status. It's not really very useful though, as you get one of two answers:

  • You are currently up to date. There is nothing else to do. Using git fetch would do nothing as well, and you would be done.
  • You are not up to date. You must get up to date so that you can rebase or merge. To do that, you must run git fetch, which will bring you up to date and then you can proceed.

Compare this to simply running git fetch, which either does nothing (you are now done) or updates you (you are now ready to rebase or merge).

torek
  • 448,244
  • 59
  • 642
  • 775
1

git status compares your local branch with what git knows about the remote branch as of the time of the last fetch/pull. Like most git commands, it does not go to the server or anything, so if someone has recently pushed some changes, it does not know about them. If you want git status to be up to date, do a git fetch first.

David Deutsch
  • 17,443
  • 4
  • 47
  • 54