Create a Dev branch and push the code from local to Dev

I have a GitHub Repo (master branch) and also different code done in local folder (with subfolders).

Now I want to use that existing repo and create a Dev branch and push all folders and files (git add .) to that Dev branch.

What is the proper way to do via terminal (commands)?

Thanks

2 answers

  • answered 2018-10-11 19:40 Stanislav Rudnichenko

    git remote add origin https://github.com/**USER**/**repo**.git
    
    git branch dev
    
    git checkout -b dev
    
    git add . 
    
    git commit -m “create dev branch”
    
    git push -u origin dev
    

  • answered 2018-10-11 20:05 Cosmin Stoica

    If your local git does not point to the remote repository, use this to add a new remote server:

    git remote add origin {insert_repository_url}
    

    If you already have that set up, though, keep reading. You need to create a new branch locally:

    git checkout -b dev_branch_name
    

    The -b tells git to create a new branch. After that, all your changes will be taken to the new branch, so you can simply:

    git add .
    git commit -m "my new changes"
    

    All your changes are now committed locally. In order to push them to your remote git repository:

    git push -u origin dev_branch_name
    

    This will also create the new branch on the remote repository and set your local branch to track that one.