0

I seem to have an issue with using git pull on a local branch. Essentially I have cloned a branch from my remote BitBucket repository, which is cloned to my USER_HOME\BRANCH directory on my machine. I want to keep this branch up to date with the remote branch. I do not make any changes to the branch on this machine. People on different machines commit their changes to this branch in bitbucket, and I want to be able to get those files without having to delete the directory and git clone all over again. Here is what i do after i have the clone.

git fetch && git checkout -b <branch>
git pull <branch> <repo_url>

Git pull generally returns "you are X commits behind origin/. It then performs the git pull, however if i go to the directory where my branch is located, none of the files have been altered. Doing a git pull immediately after returns "already up to date".

So there is a disparity between the actual folder with the files and with my git branch. I am new to git and could have easily missed something, although I have tried many things and can't get it to update the files. Any ideas?

I have tried:

git fetch origin
git reset --hard origin/master

git pull --no-ff <repo_url> <branch> 
SpencerRakoczy
  • 111
  • 2
  • 7

2 Answers2

0

This is the easiest way to achieve what you want:

First, clone the repo.

git clone https://username@bitbucket.org/username/repo.git

Then when you want to update your local copy, just run git pull

I suggest re-cloning it and just using git pull - see if that works.

brettwhiteman
  • 4,210
  • 2
  • 29
  • 38
  • That's what I've been doing. After the clone, i can see the recently committed changes from the remote by using git diff, and then do a git pull to pull those changes. But after i pull, if i go to the directory where the clone is, none of the files have been changed, they are all time stamped at the same time, which is the time that the clone was run, thus none of the files have been altered by the git pull. – SpencerRakoczy Jul 16 '15 at 21:43
  • @SpencerRakoczy hmm strange, perhaps check the filesystem permissions? I assume you have tried `git reset --hard HEAD`? – brettwhiteman Jul 16 '15 at 21:49
  • Yep i have tried git reset --hard HEAD, and also checked the permissions, unchecking the read only attribute has no effect on how git pull performs. Are there any other permissions that may have an effect? – SpencerRakoczy Jul 16 '15 at 21:53
  • Strange. Did you try a re-clone anyway? Probably best to delete the repo and do a re-clone to clean things up if you haven't already. – brettwhiteman Jul 16 '15 at 22:38
  • Could it be becuase I have been doing my git clone of the branch? I have been running git clone -b --single-branch . Would it be better maybe to clone the repo and then just checkout the branch? Would that change the files in the local repo to reflect the checked out branch? – SpencerRakoczy Jul 23 '15 at 18:05
0

You are creating a local branch that is not set-upstream-to with the remote branch.

Try:

git remote -v // To find out the name of your remote repository.
git checkout -b yourLocalBranch //Create a branch in the place you are (master).
git pull nameYourRemoteRepo/remoteBranchName yourLocalBranch // give from what remote and branch you want to pull.

Or easier:

git fetch; git checkout -b yourLocalBranch yourRemoteRepoName/remoteBranch
AlBlue
  • 23,254
  • 14
  • 71
  • 91
blashser
  • 921
  • 6
  • 13
  • my origin is set to the name of the remote repository that the branch is from. It looks like my upstream is the same as my origin, is that correct? – SpencerRakoczy Jul 16 '15 at 22:55
  • Just to clarify i saw that by doing git remote -v . It returns origin git@bitbucket.org:myUserName/myRemoteRepoName (fetch and push) and upstream git@bitbucket.org:myUserName/myRemoteRepoName (fetch and push) – SpencerRakoczy Jul 16 '15 at 22:57
  • Yes. By default, the repo from you clone, is your origin. Then where I wrote myRemoteRepoName is origin. – blashser Jul 17 '15 at 04:30