# faq-git
-
  Q: |+
    I want to work on a branch other than 'master' or 'main' of a cloned repo, do i still use git checkout -b <branch name> , ensuring the branch name matches what is already in the remote repo?
    I'm asking because the branch doesn't exist locally when I clone it, so the git checkout -b will create a new branch locally. Then when I push, it will push to the branch on the remote repo with the same name right?
  A: |+
    Good catch. Yea, do *not* use the -b option for a branch you know already exists somewhere.
    FYI, the `git checkout-b <new-branch-name>` can also take another argument, the branch you want to "copy" to the new branch. 
    So, `git checkout -b new-branch-name` is the same as `git checkout current-branch-name -b new-branch-name` (if you are on master then `current-branch-name` or `HEAD` will be `master`).
    In your case, I think you want to use `git fetch -a` to first pull down all the remote branches to your local machine.
    Then you can use `git checkout branch-name`, because the `fetch` let your local repository in `.git/` know about the remote branch.
    Once you figure it out, would be great to create some instructions in an md file somewhere for others, or add a link to a stack overflow answer that explains it somewhere in the intern learning-resources
    Normally, you use the `-b` option to create a new branch.
    That checks out the new branch locally.
    (`git checkout -b` copies whatever branch you're on into the new branch before checking it out for you)
    Then you would say `git push -u origin branch-name` to get the new branch name on the remote (gitlab).
    The `-u` option sets your local branch to automatically push to that remote and branch name in the future when you say `git push` without a destination (remote) or branch name.
    So the `git fetch -a` approach is used when you have created a branch on gitlab.com or someone else has already created a branch there.
    If you want to create a new branch yourself from the command line you use the `git checkout -b` and `git push -u` approach.
    If you created a fork rather than a branch on gitlab.com, then that's a different story entirely.
    In that case you want to add a remote on your local repository on the command line.
    That way your local repostitory knows about the new remote and you can replace origin with the new remote.
    People usually set the "mother" repo to the remote name `upstream`. 
