Pull, Add, Commit, Push ...... then Repeat
We talked about GIT, GIT Hub, and the three different areas GIT works in. Now it is time to talk about some of the most used GIT commands.
I am currently working with a team on a project called Stedman. We are all using the GIT Hub server to track our work as we make changes to the files within the Stedman project.
Many changes can be made by other members of the team, from the time I sign off to the time I sign back on. How do I get the changes they made to a file I need to work on, onto my computer?
ENTER GIT COMMANDS:
1. The first thing I do is goto my command window on my computer and navigate to the directory where the file I want to work in is located (this will be a directory that is being tracked by GIT). *If you need a quick refresher: cd file_name will take you through each of your directories until you reach your desired location. Issuing an ls command will list the files (sub-directories) in each of your directories.
2. I then need to navigate into MY Git branch that has been assigned to me to work on (There will be a future post on what this is and how it works).
3. git pull - Once I am in the correct branch, I need to "PULL" (download) the most current file from the GIT Hub repository that my team is working in. To execute the pull command, you just type 'git pull' from the directory you are wanting to work in. See the picture below to see my 'git pull' command.
Look at my 'git pull' command on the first line. Notice that before the command, it says Stedman. This is the directory I am working in. |
Remember to PULL first |
Now that I executed a 'git pull', my Git Repository is up-to-date and synched with the Git Hub Repository.
4. git status - This command lets the user know which of the three areas GIT is in. Here is an example of what this command looks like after issuing a 'git status' after doing a 'git pull'.
NOTICE the 'git status' command on the first line. It also shows that my branch is up-to-date with the GIT Hub repository (on the third line) |
5. git add <file_name> - Once I am done modifying my file on my local computer and saving it, I need to put it into the staging area of GIT. I do this by going back to my command window. I need to first make sure that I am in the correct directory that I am working in, as well as in the correct git branch for that directory. I usually do a 'git status' command right before I am about to do a 'git add your_file-name' command.
Issuing this command will allow me to then decide whether to "commit" it to my local repository, or go back and make more modifications. You will see the command I issued,
git add StedmanLesson14.html in the picture below (*don't forget to put the filename you want to add- in my case it is StedmanLesson14.html):
I immediately issue a 'git status' command to make sure the 'git add' went smoothly. The picture below will show what that looks like:
NOTICE on the first line, you see the 'git add' command. The second line the 'git status' command. |
Remember to ADD to the staging area |
6. git commit -m "place your comment here" - Once I am ready to make that commitment to saving it to my GIT repository, I issue a "git command". As you can see, there is a "-m" after the word "commit". That is so that I can leave a message about what I am committing.
NOTICE the comment "fixed spelling errors in line 399" after the '-m'. This lets myself or my team members know what this particular commit was for. |
It is good practice to always write a descriptive message about why you are issuing a 'git commit'.
GIT has now tracked my file with the new changes I made, and it is now saved in my local GIT Repository.
Remember: COMMIT saves it to your local GIT repo and gets it ready for a push |
I usually do another 'git status' to make sure my 'commit' went smoothly. Here is what that looks like:
NOTICE is recommends a "git push" to send it to the GIT Hub Repository |
7. git push - NOW I am ready to PUSH (upload) my file with the new changes/modifications to the GIT Hub repository that my team is working from. This way, everybody will have the current changes to the files. The command to issue a PUSH is simply: git push . Please see the picture below:
* I blocked out my Author information and the email that is associated with my GIT Hub account.
Once I found the commit hash number, I was able to issue the 'git revert' command.
This command took me back to my previous git push. I was able to work from there and the file was not ruined. This is the beauty of using GIT Hub, if you make a mistake in your branch, you can revert to the previous PUSH and start again.
Remember this order when using GIT:
git pull git add <file_name>
git commit -m "your comment here" git push
Follow me as I learn to build my website bit by bit! IronTreeDev.com
Photo by Bekir Dönmez on Unsplash
Photo by Alora Griffiths on Unsplash
Comments
Post a Comment