Create Local Branches With Git

Now that you have a local copy of the repository, let’s use the steps of the GitHub Flow to make a change in your project. First we will create a branch.

gif of following the directions below

  1. Create a new branch. Replace <BRANCH-NAME> with descriptive name:

     git branch <BRANCH-NAME>
    
  2. Check your repository’s status:

     git status
    

    Notice that although you created a new branch, you are still checked out to master, as indicated by the in-line response from Git.

  3. Check out to your new branch:

     git checkout <BRANCH-NAME>
    
  4. Verify that you are now checked out to your new branch:

     git status
    
Tell me why

Reviewing the GitHub Flow

Remember, we used the GitHub Flow in Introduction to GitHub, and we use it again here! :smile:

The main steps of the GitHub workflow are:

  1. Create a branch :arrow_left: (This section deals with this step.)
  2. Add commits
  3. Open a Pull Request
  4. Collaborate, and make more commits
  5. Merge the Pull Request

You learned how to create a branch in the Introduction course, too. But this time, we will do it in the local repository.

When you create a local branch, it will persist regardless of how you decide to work with your files.

Feel free to use your favorite text editor or IDE to work with your files. Rest assured that you will only be making changes on the branch you have selected.

Stuck? Open an issue in the repository for this class and mention @githubteacher for help from one of the GitHub trainers!
Continue