stevendesu
stevendesu

Reputation: 16801

Getting local master to track origin master

My git repo is in a bit of a weird place right now, so let me explain how I got here...

  1. cd /var
  2. git clone https://github.com/..... www
  3. cd www
  4. Realize I want to put the site in a sub-directory of www
  5. mkdir my-site
  6. mv !(my-site) my-site
  7. cd my-site

Now when I run git status, it claims that every single file has been deleted, and that the my-site folder is not being tracked. Kind of makes sense: I moved every single file

To try and correct this I did the following:

  1. git init -- create a new repo in "my-site"
  2. git remote add origin https://github.com/..... -- make this repo a "clone" of my origin
  3. git fetch --all -- make sure I'm aware of the most recent commits
  4. git branch -u origin/master master -- tell my local master to track origin master

When I did this I got the following error:

fatal: branch 'master' does not exist

Running git status gives me the following:

On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        ...

nothing added to commit but untracked files present (use "git add" to track)

Running git branch -a gives me:

remotes/origin/master

So I know I'm on a local master and I know a remote master exists, but I can't seem to tie the two together.

Upvotes: 2

Views: 7278

Answers (2)

James Lockhart
James Lockhart

Reputation: 1040

may be a bit long winded, but :

git checkout -b temp-branch
git branch -D master

You may want to commit files to temp-branch here or stash them

git checkout origin/master --track
git merge temp-branch

General house keeping (not necessary)

git branch -D temp-branch

It's a bit hacky, but should do the job

Upvotes: 1

Thomas Foster
Thomas Foster

Reputation: 321

There are no commits in the repo you initialised inside my-site, which is what's causing the hiccup in the git branch -u origin/master master command. You could run git reset origin/master in my-site, after which git branch -u origin/master will set the upstream as intended.

You could also blow away all contents of www and just clone the repository into www/my-site, which seems less fiddly!

Upvotes: 6

Related Questions