When you collaborate on a project using Git and GitHub, there is a prayer to the machine spirits you must follow to avoid merge conflicts.
git pull <remote server name> <branch name>
— This pulls any changes from the remote server to your local system.
git add .
— This command will add any new files that have been created to the commit.
git commit -m “describe the changes you’ve made”
— Commits your changes to the current branch.
git push <remote server name> <branch name>
— Pushes your local version of <branch name> to the remote server.
Now I’ve mentioned branch a few times, but never explained what it is.
A branch is a system to keep multiple versions of the same project available. It is particularly useful for letting multiple developers work on different features at the same time, without constantly worrying about who is editing what file, as well as keeping the live publicly deployed version separate from the working developer versions.
— Displays all available branches of the project.
git branch <new branch name>
— Creates a new branch with the given name.
git switch <branch name>
— Switches to the chosen branch.
Now when you’ve made a branch for whatever feature you’re working on, and and its ready to be merged into the main development branch.
Switch back to the development branch.
git merge <branch>
— merges any differences in the <branch> into the current branch.
And thats it! you now know how to branch off to work on a specific feature, and then merge back again.