Skip to main content

Learn Git - Git Tutorial - Part 01

 

What is GIT?

Git is a free and open-source distributed version control system that can manage everything from tiny to extremely big projects with ease.

Git is simple to understand and use, with a small footprint and lightning-quick performance. With capabilities like inexpensive local branching, accessible staging areas, and numerous workflows, it outperforms SCM solutions like Subversion, CVS, Perforce, and ClearCase.


What are you going to learn from this article?

This lesson will show you how to add a new project to Git, edit it, and share the changes with other developers.

You might want to start with the first two chapters of The Git User's Manual if you're primarily interested in using Git to download a project, for example, to test the newest version.

You can get the documentation by using 

$ git help log

Command.


How to config git username?

Before doing any action, it's a good idea to identify yourself to Git by providing your name and public email address. The simplest method is to:

$ git config --global user.name "Your Name Comes Here"
$ git config --global user.email you@yourdomain.example.com


Import a new Project

Assume you're working on a tarball project. tar.gz file containing your initial work. As seen below, you may put it under Git revision control.

$ tar xzf project.tar.gz
$ cd project
$ git init

Git Will reply

Initialized empty Git repository in .git/

You've now established an empty Git repository in.git/, and you'll see a new directory named ".git" in the working directory.

Then, with git add:, instruct Git to take a snapshot of the contents of all files in the current directory (note the.).

$ git add .

git add is a command that allows you to add files to your repository.

This snapshot is now saved in Git's "index," which is a temporary staging area. With git commit, you may save the contents of the index in the repository indefinitely:

$ git commit

You'll be prompted for a commit message. 

You've just saved your project's first version in Git.

Making Changes

Modify a few files, then update the index to reflect the changes:  
$ git add file1 file2 file3

You are now prepared to make a commitment. With the --cached option, you can view what's about to be committed with git diff: 

$ git diff --cached

(Without —cached, git diff will display any changes you've made but haven't yet indexed.) You may also use git status to get a quick overview of the situation: 

$ git status
On branch master
Changes to be committed:
Your branch is up to date with 'origin/master'.
  (use "git restore --staged <file>..." to unstage)

	modified:   file1
	modified:   file2
	modified:   file3

If you need to make any further changes, do so now and then update the index with the updated material. Finally, save your modifications by typing: 

$ git commit

This will prompt you for another message describing the change, after which you will be prompted to record a new version of the project. 

You may also use git add instead of executing git add first. 

$ git commit -a
This command will detect any changed (but not new) files, index them, and commit them all in one step. 

A word on commit messages: It's a good idea to start the commit message with a single brief (less than 50 characters) line describing the change, followed by a blank line, and then a more detailed description, even if it's not needed. The content in a commit message up to the first blank line is interpreted as the commit title, which is used throughout Git. For example, git-format-patch[1] converts a commit into an email, with the title appearing on the Subject line and the remainder of the commit appearing in the body. 


View Project History
You may check the history of your modifications at any time. 
$ git log
If you'd want to view complete differences at each stage, use  
$ git log -p
A summary of the transition is frequently helpful in getting a sense of each phase. 
$ git log --stat --summary

Managing Branches
Multiple development branches can be maintained in a single Git repository. Use the command to establish a new branch called "experimental." 
$ git branch experimental
If you now run
$ git branch
You'll be given a list of all branches that are currently active: 
 experimental
* master
The "experimental" branch is the one you just made, whereas the "master" branch is a default branch that was automatically established for you. The asterisk denotes the branch you're on right now, type 
$ git switch experimental
To go along the experimental path Now make a modification to a file, commit it, and switch back to the master branch: 
(edit file)
$ git commit -a
$ git switch master
Since you were on the experimental branch and are now on the master branch, double-check that the modification you made is no longer visible. 
On the master branch, you may make the following change: 
(edit file)
$ git commit -a
At this time, the two branches have separated, with each branch undergoing its own set of alterations. Run this command to merge the modifications made in experimental into master. 
$ git merge experimental
You're done if the adjustments don't conflict. If there are any discrepancies, markers will be placed in the issue files to indicate the discrepancy. 
$ git diff
This will be demonstrated. After you've resolved the issues by editing the files, 
$ git commit -a
will commit the merge's outcome. Finally, 
$ gitk
will display a good graphical depiction of history as a consequence. 

You could delete the experimental branch at this time.
$ git branch -d experimental
This command guarantees that the experimental branch's modifications have already been included in the current branch.

If you construct a crazy-idea branch and then regret it, you may always delete it with

$ git branch -D crazy-idea
Branches are inexpensive and simple to use, so this is a nice method to experiment.

In the next part of this tutorial, we'll learn more about Git. Leave a comment below if you have any questions or comments.

Comments

Popular posts from this blog

 Machine Learning           What is machine learning? Machine learning (ML) is a sort of artificial intelligence (AI) that allows software programs to improve their prediction accuracy without being expressly designed to do so. In order to forecast new output values, machine learning algorithms use past data as input. Machine learning is frequently used in recommendation engines. Fraud detection, spam filtering, malware threat detection, business process automation (BPA), and predictive maintenance are all common applications. Why is machine learning important? Machine learning is significant because it allows businesses to see trends in consumer behavior and operational patterns, as well as aid in the creation of new goods. Machine learning is a major aspect of the operations of many of today's leading organizations, like Facebook, Google, and Uber. For many businesses, machine learning has become a key differentiation. What are the different types of mach...

Spring Boot Tutorial ( beginners to professionals) part -1

 Spring Boot Tutorial  This Spring boot tutorial provides you to complete lessons from beginning to professional. This spring boot tutorial is help full even you know nothing about Spring boot we going to cover all topics of Spring boot such as Advantages, history, maven, starter project wizard, spring initializer, how to create a  new spring boot project,  spring boot annotations, Spring boot dependency management, crud repository, JPA repository, etc.

Express (part-1)

 When building web apps using Node.js, setting up a server might take a long time. Because of the community's support, Node.js has matured enough over time.  Using Node.js as a backend for web apps and websites allows developers to get started quickly on their project. In this article, we'll look at Express, a Node.js web development framework that includes capabilities like routing and rendering, as well as support for REST APIs.