Workflow to explore Git branching and merging with a local repository
Start on the main branch (usually called master or main). Check it with
git branch, the main branch will be marked with an *.
Create a new branch called "feature" -
git branch feature
Switch to the feature branch -
git checkout feature
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"
Switch back to main -
git checkout master
Merge the feature branch into main -
git merge feature
This will create a new commit on main with all the changes from feature.
Check that main contains the changes with
Delete the feature branch since the changes are integrated -
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.