Once you were able to properly authenticate and clone (download) a repository you have a read/write access to, it’s time to create a new branch.
Why create a branch?
it’s same as creating your own copy of an original document so you can make changes to the document without affecting the original one.
Let’s create a new branch. The assumption is that the repository is already cloned and you have access to the repository.
Check which branch you are on (very important!).
this is what I do before anything. The current branch is indicated with an asterisk (*) in front of the branch name. If you just cloned it, the current (and only) branch will be either main or master.
git branch #check current branch
git checkout anotherbranch #go to branch called "anotherbranch"
Create a new branch. I named the new branch dev. Check to see if you correctly created branch named dev and you are currently on that branch
git checkout -b dev # creating new branch
git branch # print all branches and current branch with *
Commit new changes in dev branch. You can go back and forth between branches but if you have changes you didn’t commit, you have to do something (like commit) before going to (checkout) other branch.
git add . # stage all changes
git commit -m 'created new training module reprojection'
Merge process.. Before I merge anything, I want to make sure the main branch is up to date in case anyone made any changes until this point. I am pulling (fetching and merging) the most up to date main branch from the remote repository
git checkout main # now go back to main branch
git pull origin main # download most up to date main branch from github
git merge dev # now merge my dev changes with the main branch
If someone made changes that affect your change, there could be discrepancies which doesn’t allow you to merge. You need to manually merge them to make sense to you and others who made changes. Once changes are done and committed, you can then merge to the main branch.
Upload your new branch to github
git push origin dev