This is a list of the commands I use most frequently in a normal work day as developer.
1.- To clone an existing repository on your computer:
Let’s suppose that this is the project that we want to have in our computer
react_project is the name of the project
Run this code in your terminal:
git clone projectUrl
Copy this project url:
2.- Let’s suppose that we need to work in one ticket that is assigned to us, for example the ticket number: #30 description: “create a index.js” and at this point our tech lead required us to make this change in a different branch, instead of master branch.
Let’s create a new branch from master called feature/30-index-file, run this code in your terminal
git checkout -b nameOfDeNewBranch
3.- Let’s assume that we already finished the ticket (in our code editor)
And we want to upload the changes to Github, so write this command in the terminal to see if our changes are reflected in the terminal
At the same time we will see this message that show our created file in red color that means that the file is “untracked” and the next step add the changes to the the stage.
8.- So, to add the changes (the file) to the stage we need to run the next command
git add fileName
Note: if we want to add multiple files just type “git add . “
7.- Let’s commit our changes, so for this we need to run the next command
git commit -m "some message that describe this commit"
Note: after this command, type again “git status” you will see that we don’t have nothing to commit at this point so this is good!
8. Ok, to push(upload) the changes to GitHub branch we need to run the next command
git push origin nameOfTheBranch
9.- The next step is create a Pull Request (commonly abbreviated as PR), so go to your your browser and open the project “react_project” in your GitHub (or refresh the page), now you will see that our created branch is there in yellow color:
So, click the green button [Compare & pull request] to create the PR
At this point we need to make sure what is the name of the branch that we want to merge your changes (the base) in my case will be the “master” branch.
So basically this means that I’m going to merge or insert the changes that I have in my branch “feature/30-index-file” to branch “master” That’s about it.
Also, we have a text-area where we can add more description about our changes, in my case I like to upload images of my changes especially when the changes are UI, styles, look of some project, etc.
So, just drag and drop the image that you want to show into the text-area.
Then click on the green button [Create pull request]
Finally you can assign the PR to some team member that can help you reviewing your PR (This is a good practice).
Cool, now if your PR was approved by your manager or team member and you don’t have conflicts between branches you can click on green button [Merge pull request]
When you clicked on merge this means that your changes now are in master branch!
In the next post I will show you how to resolve conflicts in GitHub in case of you have some.
By Cristina Rojas.