Version control is a type of system that allows you to keep track of changes made to your code over time. As such, version control is useful because:
1)You can revert back to specific ‘versions’ of your code
2)Collaboration on the same work is possible because specific changes and associated contributors are tracked
Basic Steps
1)To list all branches in the repository:
- git branch
2)To create a new branch:
- git branch new-branch-name
3)This will only create the branch. To switch to a specific branch and start working within it:
- git checkout another-branch
4)Alternatively, if you want to create a new branch and immediately switch to it:
- git checkout -b new-branch-name
Merging Branches
To merge two branches (on your local repository) such as a feature branch and the master branch:
1)Ensure you are on the receiving branch (master would receive from feature branch)
- git checkout master
2)Both the feature and master branches must be completely up-to-date, including with remote changes
To pull and merge the most recent remote changes:
- git pull
3)To merge the feature branch into the master branch:
- git merge feature-branch
4)Delete the now-irrelevant feature branch
- git branch -d feature-branch