Reputation: 563
TLDR: I set-up a local remote but it seems to work for pushing and pulling but not very well for syncing..
Here are the details.
I learn a little about working with remote.
So I want to use git locally both for my working directory but also as my remote repo (in place of a service like Github).
For this I first initialized my first (working) project repo :
#[~/project/project_ABC] → git init
After some work on it I add and commit all my work so I end up with a clean working directory repo.
But instead of pushing this work on a web remote service (like Github) I wanted to actually host the remote locally.
So I bare initialize a repo on a dedicated folder (paying attention to name it with the .git suffix) :
#[~/repos/project_ABC.git] → git init --bare
Then, coming back to my working directory, I push my work to this "remote" repo after adding it to my list of remote repo :
#[~/project/project_ABC] → git remote add local ~/repos/project_ABC.git
#[~/project/project_ABC] → git push local master
At this time when I git status -uno
I get that everything is good...
To test that this "remote" repo is actually working I made some change to my work in my working directory and commit them (in the working directory).
So at this time if I git status -uno
I get that my branch is ahead of 'local/master' by 1 commit.
Yay..Pushing to that repo seems working..
So I git push
my work and everything is good.
But I also wanted to try that pulling from this repo works too..
So I git clone from this local "remote" repo to another working directory and made some changes (and in this case the remote is named origin
as it should be:
#[~/test] → git clone ~/repos/project_ABC
... made some changes, committing and then pushing to remote
#[~/test/project_ABC] → git push origin master
Here is the fancy part!
Back to my original working directory I expect that when I git status -uno
to get the message that my branch is behind of "local/master" by 1 commit.
But nope!
I get the message that my branch is up-to-date with local/master.
So what's going on here ?
Thank you in advance. And sorry for my bad english..
Upvotes: 2
Views: 72
Reputation: 520918
What is going on here is that git status
only shows the information it actually knows, which is a comparison of your local branch against its local tracking branch which tracks the actual remote branch. When you pushed a commit to the local repo from the second clone, Git did not know about this because the tracking branch was not synched.
To get around this, you should make the habit of doing a git fetch
before you do git status
. So if, from your original working directory, you had done the following:
git fetch origin master
git status
then I expect you would have seen:
branch is behind of "local/master" by 1 commit
Upvotes: 1