Getting started with GIT – Part 4

Welcome Back!!! to the part 4 of git tutorial series. This part is going to be a short one. In previous parts we used some text files as our project. In this tutorial we are trying work with a small project. For the project I am going to use a basic HTML website I made.


  • So, first thing we need to do is turning our normal folder which contains project files into git project.
  • So, I am going to open up the git bash and navigate to the project folder using “cd” command.


  • Initiate the git repository using the command “git init”.
  • Now try “git status” command. You will notice that we have our files listed under untracked files.


  • So, we should add those files using “git add” command.


  • Period is used to add all the files.
  • Then we should commit.

  • Now, all set for learning new stuff.

Let’s learn how to undo changes done to our working directory.

  • First let’s look at the current status of our website.


  • Let’s say I accidentally changed position property of <h3> element to fixed. (you can change whatever you want).


  • So, I now messed up my code. So, I need to undo whatever the changes I made to the file.
  • So, I need to take the files from the repository and replace them with my messed-up files.
  • First thing we are going to do is entering the command “git status” to check current status.


  • You can see git says that we modified the style.css file. Now we need to take files from the repository and replace them with my working copy. To achieve it we use “git checkout -- <file name>” command.


  • If you enter “git status” command, you will notice that says that our working copy and the repository are same now.

  • If we refresh our website, you can see the it is also came back to the previous stage.


Let’s learn how to unstage files.

  • Let’s assume I decided to change the background color of my website to light blue.




  • After changing the color, I am going to add the changes to the staging area.


  • Now I enter the git status command to check whether modified files are added to the staging area.


  • After all these scenarios now, I feel like that the background color that was there earlier is better.
  • Now I want to remove the file from the staging area and bring it back to my working copy. Simply I want to unstage the file. We can do so by using “git reset HEAD <file name>” command.


  • Now if I check the status you can see that the file is unstaged.



  • Okay, it is the end of part 3. Lets meet with the next part of the tutorial. :)






Comments

Popular Posts

Getting started with GIT – Part 3

Getting started with GIT – Part 2

Getting started with GIT – Part 5