Skip to main content

Basic Git Commands

 Basic Git Commands


Objectives and Outcomes

In this exercise you will get familiar with some basic Git commands. At the end of this exercise you will be able to:

  • Set up a folder as a Git repository

  • Perform basic Git operations on your Git repository

Basic Git Commands

  • At a convenient location on your computer, create a folder named git-test.

  • Open this git-test folder in your favorite editor.

  • Add a file named index.html to this folder, and add the following HTML code to this file:

Initializing the folder as a Git repository

Go to the git-test folder in your cmd window/terminal and type the following at the prompt to initialize the folder as a Git repository:

Checking your Git repository status

Type the following at the prompt to check your Git repository's status:

Adding files to the staging area

To add files to the staging area of your Git repository, type:

Commiting to the Git repository

To commit the current staging area to your Git repository, type:

Checking the log of Git commits

  • To check the log of the commits to your Git repository, type:


Now, modify the index.html file as follows:
  • Add a sub-folder named templates to your git-test folder, and then add a file named test.html to the templates folder.
  • Then set the contents of this file to be the same as the index.html file above.
  • Then check the status and add all the files to the staging area.
  • Then do the second commit to your repository

Now, modify the index.html file as follows:
Now add the modified index.html file to the staging area and then do a third commit.

Checking out a file from an earlier commit

To check out the index.html from the second commit, find the number of the second commit using the git log, and then type the following at the prompt:

Resetting the Git repository

To discard the effect of the previous operation and restore index.html to its state at the end of the third commit, type:

Then type the following at the prompt:

You can also use git reset to reset the staging area to the last commit without disturbing the working directory. Conclusions At the end of this exercise you should have learnt some basic Git commands. Experiment with these commands until you fully understand how to use Git.

Comments

Popular posts from this blog

HTML Tutorial for Web Development and Design

HTML Tutorial for Web Development and Design HTML is the language of web  the structure of web pages is created with the help of Html  it is styled with the help of css  and logic is added to it with the help of javascript.  In 1989, Tim Berners-Lee established the http://www  and he created the Html in 1991.  Html was a very basic language at that time  which did not even have an image tag  well it is still a basic language even in today's time. In 1991, when other programming languages  were evolving in different fields  then Tim Berners-Lee thought that  it is very important to have a language for web developers as well  and it is very important to have a standard  he took it forward giving full support to html  and understood the problem of web developers  and those who were developing the browser  he sincerely wanted that  a modernization could come in the world of web development  and the pro...

CSS Web Development Tutorials

Learn CSS for free - A tutorial for beginners CSS (Cascading Style Sheets) makes pages look great and adequate. It's a fundamental piece of current web improvement and an absolute necessity have expertise for any website specialist and engineer. In this article, I'll give you a speedy prologue to assist you with getting everything rolling with CSS. I'm accepting that you have a fundamental comprehension of HTML , however other than that there are no requirements for this instructional exercise. Welcome to Learn CSS: This course breaks down the essentials of CSS into edible, straightforward pieces. Throughout the following couple of modules, you'll figure out how the center parts of CSS work and how to utilize them really in your tasks. Utilize the menu sheet by the "Learn CSS" logo to explore the modules. You'll learn CSS essentials like the container model, outpouring and particularity, flexbox, lattice and z-file. Furthermore, alongside these essentials,...

Javascript For Web Development

           Basic Javascript For Web Development What will you learn in this JavaScript Tutorial for Beginners? In this JavaScript rudiments for novices instructional exercise, you will find out about certain basics of JavaScript like Variables, Arrays, loops, Conditional Statements, Cookies, and so on, and some high level JavaScript ideas like DOM, down to earth code models, JavaScript Unit testing system, calculatios, and so on. Are there any prerequisites for this JavaScript Tutorial? Nothing! This is an outright JavaScript fledgling manual for learn JavaScript with models. In any case, assuming that you have some fundamental information on HTML and CSS, it will assist you with learning quicker and all the more productiviely. Who is this JavaScript Tutorial for? This JavaScript for fledglings instructional exercise is for understudies who need to find out about Web Application improvement and programming advancement. This instructional exercise is additio...