Learn Git within 7 Minutes and Play Around with It

Yesterday, I watched a VDO on somkiat.cc about Git for beginner and I found it is really interesting especially for those who new to Git (like me! 😅). The video is from CodingDojo.

Here is the infographic published on their page.

So let’s play around with it! But first thing to do is to install Git client from here. Once installed then you are ready to play.

1. Let’s find a folder you want to make a backup with Git or you can create a new one. This folder is called working directory. Here I created a folder “demo-git” and create new 3 text files in there.

Here are the content in those files:

2. Create local Git repository using command git init

3. Add files to staging area using command git add .

4. Commit your files into your local Git repository by using command git commit -m “Initial Commit”

Now you have a backup of your files in your local Git repository.

5. Let’s make change to the File 2.txt and File 3.txt and use command git status

This will show which files have been modified since the last commit.

6. Add modified files to staging area by this command git add .

7. Use command git status again

Now you modified files are now in staging area and ready to commit.

8. Use command git commit -m “Updated File 2 and 3” to commit your changes to local Git repository.

9. If you use command git status again, it will say there’s no more change to commit.

10. Use command git log to display commit log information

11. you can use command git show to display the changes from the last commit.

12. You can revert changes to previous commit by using command git checkout <current commit name>~1

If you use command git status again you will see this:

13. Next, you want to push your local repository into your remote repository so someone else can work on your files. First thing, you need to create a new repository on GitHub (Sign up first if you don’t have an account yet.).

14. Input your repository name and click Create repository

15. Copy your Git repository URL

16. Use command git remote add origin <repository URL> to add a new remote repository named “origin” to your local repository

If you use command git remote now, you should see “origin” in the list

17. Let’s get back to the latest commit by using command git checkout master

18. Use command git push --set-upstream origin master to push files to your remote Git repository

If you use command git status you will that your local repository is up-to-date with your remote repository.

19. Try to make some changes on GitHub.

20. Use command git fetch to get the latest data from remote repository

If you use command git status again now, you will see that your local repository is now behind your remote repository

21. Use command git pull to load all changes from remote repository to your local repository.

Now, your working directory and local repository should be at the same version as in remote repository. You can check that by using command git status

Related Blog

Learn More

Originally published at pacroy.blogspot.com on January 2, 2017.