Git can be a scary place And if you don't have a workflow properly set up you could end up losing a lot of precious work to a merging error. Here is how I go about my git workflow when working with another collaborator.
Your primary workflow will revolve around setting up a plan with your partner. Make sure that you each know what you will be working on so that you don't end up stepping on each other's toes, I would suggest utilizing some organizational tools like Trello for this.
Create your GitHub repo and clone it using
>Git clone “your clone link”
This will create a new directory with your new repo. cd into the repo and create your first branch for working on your project using the following commands.
>$Git checkout -b “Branch-Name-Here”
> $Git add .
You should now be able to see a new branch on your Github repo!
Git checkout -b creates a new branch for you to work on your own feature, branches are important as they keep us from destroying our stable product while allowing us to test and add new features!
Your next step should be to work on the feature you and your partner agreed on. when you’re done coding you’re gonna want to run the following commands in your terminal-
>$Git add .
>$Git commit -m “Your message on what you worked on here”
>$Git push “Your branch name” / $Git push
what this does is commit your repo change to your branch’s GitHub repository, this helps us with version management and now in the case that you accidentally delete something from your code and have no way of getting it back you can retrieve it from your Github Repo!
After you have your feature worked out and you’re ready to push to master run the code
>$git add .
>$git commit -m “Final-Commit-to-explain-branch”
>$git push origin master
Oh no! we've run into an error here, it turns out that our partner on the project pulled some new code into the master branch before us. this is resolved easily though by running:
>$git pull origin master
in order to pull all of the master code into your current working environment
walla! now we can head over to GitHub to create a pull request and enjoy the fruits of our labor by having an updated master branch!
Moving forward make sure that you always create a branch when adding code to your project and never code directly to the master branch, its just good practice, and make sure to keep in contact with your partner about what you do in the project to keep everyone in the loop!