Workflow to explore Git branching and merging with a local repository

Workflow to explore Git branching and merging with a local repository

ยท

1 min read

  1. Start on the main branch (usually called master or main). Check it with git branch, the main branch will be marked with an *.

  2. Create a new branch called "feature" - git branch feature

  3. Switch to the feature branch - git checkout feature

  4. Make some commits on the feature branch to change files, for example:

     # Add a new file 
     vim newfile.txt
     git add newfile.txt
     git commit -m "Add newfile in feature branch"
    

     # Edit existing file
     echo "Some feature code" >> README.md 
     git commit -am "Update README for new feature"
    

  5. Switch back to main - git checkout master

  6. Merge the feature branch into main - git merge feature

    This will create a new commit on main with all the changes from feature.

  7. Check that main contains the changes with git log

  8. Delete the feature branch since the changes are integrated - git branch

    -d feature

Overall, using a local Git repository provides flexibility and speed benefits compared to only using a remote repo. The local repo is the main development hub. Remotes like GitHub enable collaboration, visibility and backup of commits.

ย