title: connect a local repo to a new branch on a remote repo
body: <p>I have a remote GitLab repo <code>my-project</code> that contains 2 branches <code>master</code> and <code>dev</code>. And I have a directory on my local machine named also <code>my-project</code> that I was developing some code in it and it has more or less the same structure as the remote repo. What I want to do is:</p>
  <ol>
  <li>initialise the directory as a git repo (which I already did)</li>
  <li>connect the initialised local repo somehow to the remote one.</li>
  <li>Then create a branch based on the structure of the <code>master</code> branch of the remote repo (without losing any files on the local repo).</li>
  <li>finally, push the code in the local repo to the newly created branch in the new repo.</li>
  </ol>
  <p>what I have done so far is:</p>
  <pre><code>cd my-project
  git init
  git fetch
  git checkout -b new_dev_branch
  git add .
  git commit -m &quot;first trial&quot;
  git remote add origin path/to/remote/gitlab/my-project.git
  git push -u origin new_dev_branch
  </code></pre>
  <p>But the problem is that it didn't create the branch with the structure of the master as I wanted in step 3.</p>
  <p>Any ideas?</p>