Setting Up Git And Commands To Checkpoint Your Code To Save Time
Hello guys, welcome back to my blog. In this article, I will discuss setting up git, basic commands, commands to checkpoint your code to save time, I will share some example like adding code and changing it.
If you need an article on some other topics then click on ask questions and add your question. You can also catch me @ Instagram – Chetan Shidling.
Also, read:
- MATLAB Programming Tutorials For Beginners With Examples.
- File Operation In C Programming With Explanation And Code.
- Internship For Engineers, Some Tips To Take Internship Anywhere.
Setting Up Git
Git is version control. Version control means software tools that enable the management of changes to the source code. This means it will maintain history. Suppose if you make some changes in your source code and it went wrong then you can go back to the previous source code with the help of version control tools.
In this article you will learn.
- Install Git on your computer
- Assure that Git can be handled from the command-line or command-prompt on your computer
- Set up some of the basic global configurations for Git
Downloading and Installing Git
- To install Git on your machine, go to https://git-scm.com/downloads to download the Git installer for your particular computing platform.
- Then, understand the installation steps as you install Git using the installer.
- You can find more details about installing Git at https://git-scm.com/book/en/v2/Getting-Started-Installing-Git. This document lists different methods of installing Git on different platforms.
- Installing any of the GUI tools like GitHub Desktop will likewise install Git on your computer.
- On a Mac, setting up XCode command-line tools too will set up Git on your computer.
- You can take any of the ways that are most convenient for you.
Some Global Configuration for Git
- Begin a cmd window or terminal on your computer.
- Check to get sure that Git is installed and available on the command line, by copying the following at the command prompt:
git --version
To configure the user name to be employed by Git, type the below command at the prompt:
git config --global user.name "Your Name"
To configure your email to be utilized by Git, type the below command at the prompt:
git config --global user.email <your email address>
You can check your default Git global configuration, you can type the below command at the prompt:
git config --list
After this exercise you will have Git available on the command-line of your PC or laptop.
Basic Git Commands
In this article you will get familiar with some basic Git commands. At the end of this article you will be able to:
- Set up a folder as a Git repository
- Conduct basic Git operations on your Git repository
Git Commands
- At an accessible location on your laptop, create a folder named git-test.
- Open this git-test folder in your preferred editor like VS Code, sublime text editor.
- Add a file named index.html to this folder, and type the HTML code that is given below to this file:
<!DOCTYPE html>
<html>
<head>
<title>Chetan Shidling</title>
</head>
<body>
<h1>This is a Header</h1>
</body>
</html>
Initializing the folder as a Git repository
- Go to the git-test folder in your cmd window/terminal and type the below command at the prompt to initialize the folder as a Git repository:
git init
Checking your Git repository status
- Type the below command at the prompt to check your Git repository’s status:
git status
Adding files to the staging area
- To add files to the staging area of your Git repository, type the below command:
git add .
Commiting to the Git repository
- To commit the current staging area to your Git repository, type the below command:
git commit -m "first commit"
Checking the log of Git commits
- To check the log of the commits to your Git repository, type the below command:
git log --oneline
Now, change the index.html file as follows:
<!DOCTYPE html>
<html>
<head>
<title>Chetan Shidling</title>
</head>
<body>
<h1>This is a Header</h1>
<p>This is a paragraph</p>
</body>
</html>
- Add a sub-folder named templates or any other name to your git-test folder, and then attach a file named test.html to the templates folder. Then add HTML code to this file to be the same as the index.html file above.
- Then check the status of current and add all the files to the staging area.
- Then by using the command do the second commit to your repository
- Now, modify the index.html file as follows:
<!DOCTYPE html>
<html>
<head>
<title>Chetan Shidling</title>
</head>
<body>
<h1>This is a Header</h1>
<p>This is a paragraph</p>
<p>This is a second paragraph</p>
</body>
</html>
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, get the number of the second commit using the git log, and then type the below command at the prompt:
git checkout <second commit's number> index.html
Resetting the Git repository
- To avoid the effect of the previous operation and restore index.html to its state at the end of the third commit, type the below command:
git reset HEAD index.html
- Then type the following at the prompt:
git checkout -- index.html
You can also use git reset to reset the staging area to the last commit without disrupting the working directory. Experiment with these commands until you fully understand how to use Git.
I hope this article may help you all a lot. Thank you for reading. If you have any doubts related to this article “Setting Up Git”, then click on ask questions.
Also, read:
- 100+ C Programming Projects With Source Code, Coding Projects Ideas
- 1000+ Interview Questions On Java, Java Interview Questions, Freshers
- App Developers, Skills, Job Profiles, Scope, Companies, Salary
- Applications Of Artificial Intelligence (AI) In Renewable Energy
- Applications Of Artificial Intelligence, AI Applications, What Is AI
- Applications Of Data Structures And Algorithms In The Real World
- Array Operations In Data Structure And Algorithms Using C Programming
- Artificial Intelligence Scope, Companies, Salary, Roles, Jobs
- AWS Lambda, Working, Cost, Advantages, Disadvantages
- AWS Technical Interview Questions, Top 200+ AWS Questions
- Battery Management Systems Using Artificial Intelligence
- Best Engineering Branch For Future
- Best Programming Languages For Electrical and Electronics Engineers
- Big Data, Evolution Of Big Data, Benefits Of Big Data, Opportunities
- Bit Operation In C Programming With Example & Applications
- Blockchain Projects For Computer Science Engineers
- Blockchain Technology, History, Working, Applications, Advantages
- Brain Computer Interfaces Technology, Beyond AI, ML, IoT, Blockchain
- C Language Interview Questions On Programs With Output
- C Program On Arrays With Output For Placement Exams