The Elmira Cheat Sheet to learn Git

all you need to know about git

Learning Git is no longer optional but a necessary and essential part of software development. If you are going to a Tech Job interview, 99% chances are that they will ask about Git and GitHub. No reasons for them that they will reject you on the basis of this Question but it will give a good impression to the interviewer if you know about Git and Git Hub. 

What is Git anyway?

Git is abbreviated from three words "Global Information Tracker", which by itself gives the complete purpose of Git. In simple words, "Git is a Version Control System.". There are though many software used for version controlling in software development, then why use Git?. Well, there are reasons to use git over other Version Control Softwares.

Why you should use Git Over other VCS?

Git is Free and Opensource and after all the most famous version control system, built to handle your Projects. The big reason for using Git over other VCS (version control Software) is the popularity and Global use of Git. 

But Why is Git so widely used?

  Git has some features that are not available in other VCS (version control software) and this is the reason for the popularity of Git. I will mention a few of them.

  • Compatible with existing systems and protocols ( HTTP, FTP, ssh)
  • Cryptographic authentication of history
  • Git is fast and efficient in Performance
  • Easy Tracking System
  • Having an amazing Command Line Tool (CMD) Git Bash
  • Having Git GUI
  • Git is Cross-Platform
  • Git is Opensource and Free

How can I learn Git?

Learning Git is Easy with The Famous Elmira Cheat Sheet for Learning Git. People are having hours of sessions in schools and colleges to learn Git and Github and I can understand this. They have to make Git the most difficult and complex topic, which I do not think is difficult. All you should know is some commands and then you need some practice. I will introduce you to the commands compiled by Elmira.

The Elmira Cheat Sheet for Learning Git

Elmira Compiled the list of Git commands in a cheat sheet which I think can make it easy and simple to learn Git. Using The Elmira Cheat Sheet for Learning Git can help you memorize these git commands very easily. 

Elmira living in Sweeden, is a Full-Stack Developer and Student. Elmira is Interested in App and Web Development. If you are Learning App Development or Web development, Follow Elmira on Twitter for tips & resources.


How to learn Git Commands?

By using the Elmira Cheat Sheet, you can learn the Git commands in a very short time. She has divided the git commands into 4 categories. So think of the Git commands in a categorical way. Learn  Git Basic Command, Git Branching, and Merging, Learn about Making a change with Git, and after that learn about the Synchronization command. I will explain each of them in a detail. Install Git and then practice the following command.

Git Basic Commands:-

These are simple commands that you can start with. Just apply these commands on the Git Command-line interface. I will show you all of them with the help of an example at the end of the article.

git init:-

The git init command is used to create a new local Git repository. The git command can also be used to convert an unversioned project to a git repository. This is the first command and is used to create a local repository. To work ahead you just need to initialize a repository. Most of the commands are not available outside of the git repository, so that's why you will need to have a git repository. 

Create a git repository with git init:- 

git init command

with the git init command we can just create an empty git repository. which will add a .git subdirectory to the current directory. the .git repository contains the metadata and configuration of the git repository.

Convert a Project to git Repository:-

Suppose you have an unversioned Project and you want to transform this project into a git repository, you will need the help of the git init <directory> command. 

convert a project into git repository

Here is a depth article Explaining the work of the Git init command. If you need to be the master you definitely need to learn more about the git init command. 

git clone:-

When you need to copy a git repository that is already created with git, then use the git clone command.  It can be used for cloning a remote or a local repository. git clone command can also help you clone a repository partially. 

Clone a git remote repository:-

To clone a remote repository with a git clone can be done by the supported protocols. if you are cloning a GitHub repository, then Github gives you two protocols for the option. one is ssh and the other is HTTPS. you can use any of them as a URL to the remote repository. 

clone a remote git repository with git

If you feel the need to learn more about the git clone command, then here is a complete tutorial of the git clone command. 

git add:-

When you made some changes to a git repository, then you will need to use the git add command to add these changes to the git repository. This way git will know to include updates to a particular file in the next commit. The git add command and git commit command are two commands that every git user should know about. 

Add a file to a git repository using git add:-

You can add a single file with the help of the git add <file_name> command. This will mean to stage all the changes to this file in the next commit.

adding a sinlge file to git repository

Add a Directory to a git repository using git add:- 

Same as adding a file you can also add a repository all it once to the git repository.  It will stage all changes to the directory in the next commit.

adding a dirctory to git

Add all files and directories to the git repository:-

if you are lazy to add every file and directory individually, you can use dot to add all of the files and directories in just one command. 

adding all file to git

If you want to know more about the git add command. I will give a reference to this article related to git add

git commit:-

The git commit command is used to create a snapshot of the staged changes which will be added to the history of the git Project. git commit has a few parameters that serve different purposes. 

git commit with no parameters:-

Normally you will run this command to commit changes, but every commit needs to have a message. so git commit with no params will open a text editor where you should write some text, save and close it. 

git commit

Commit with a Proper message:- 

In the above case you will be prompted by a file to write your message in but why not write a commit message in the same command. to serve this purpose there is an optional parameter -m while helping you write your message alongside. you will have to write your message enclosed in double quotation. 

commiting with a message

Do you need a reference to a Complete article to learn Git commit command? Click on the colored text it will lead you to a comprehensive article related to git commit. 

git push:-

When you are done with some part of the project and want to upload them to a remote repository then you need to use the git push command. 

push changes to a git repository
A comprehensive article on git push is attached. 

Git Branching and Merging Command:-

When you are working in a team, you will need to clone the project and create a separate branch of the same project for yourself. You will be made to your branch of the project and at one time you will need to merge your branch to the main branch. In this scenario, you will take the help of the following commands.

git branch:- 

This is the command which is used for creating, listing, renaming, and deleting branches of the git repository. the git branch command is used with the association of git merge and get checkout commands.Branching in other VCS can be expensive operaton but with git it is easy and take less time. 

Show all braches of a git repository:-

To show the braches of the git repository you can use either git branch or git branch --list. both of them functons the same. 

git branch command

Delete a branch of git repository:- 

To delter a branch form git repository, you have two options. The branch may have changes that are unmergerd but with git branch -d <branch> you can deleter branch if it has not unmerged changes. in this case you need to use "D" to force delte the branch.

Delete a branch using git

Branching is somehow difficult to understand, read this in depth article to learn more about git branch command.

git checkout:-

When you have different branches in a git repository, then you will need to take the help of the git checkout command to navigate between the branches. 

git chekout

git merge:-

The git merge is the complicated one among all of the commands listed and the reason is that git merge creates "conflict". git merge combines multiple sequences of commit into one unified history. To make things simple the git merge is used to merge two branches of the git repository. 

You need to navigate to the branch where you want the other branch to merge. the you have to use the merge command and it will merge that branch to the current branch that you are working in. 

merging two branches of git

git log:-

This command is used for listing the commits that are made to a repository.

git log command

 

Make a change Commands:-

The following are the commands that are used to see or make any changes to a git repository. They are the most easied of all. 

git status:-

Use this command if you want to see the state of the working directory. 

git status

git diff:-

As from the name the Git diff command is used to display the difference between files in two different commit of a commit and the current repository in which you are working on. This way you will see the difference between the two. 

see the uncommited changes to a git repo

git reset [file]:- 

Git rest is used to undo changes that are made to the state of a local repository. 

git reset changes

Git command to Synchronize Repository:-

git remote add <name> <url>:- This command is used to add a new remote for the repository that you are working in. you need a remote repository in order to push changes. 

git fetch:- 

When you are working on different branches and you want to download the contents from a repository you need to use the git fetch command. 

git fetch command

git pull:-

Once you make changes to a repository and push them to the remote. then others will need to use the git pull command to view the changes that you have made in the meantime. 


Summary and Conclusion:-

As I mentioned earlier, Learning git is not that hard if you just practice it. So I mentioned all of the commaans that you might need it in day to day in your software development career. If you have any questoins in mind please feel free to ask them in the comment section. Finally I would like to think Elmira for creating the cheat sheet. 

AlixaProDev

I’m Ali, Founder of alixaprodev.com. I am a Software developer, and I love to write articles to help students, developers, and learners. I started alixaprodev.com because of my love for Python, Java, and WebDev.

Post a Comment (0)
Previous Post Next Post