Instagram
youtube
Facebook
  • 2 years, 3 months ago
  • 3343 Views

Everything about Git

Mradul Mishra
Table of Contents

Hello all, in this blog. We are going to learn about the top git commands and their usage. Git is a free and open-source software for controlling the version of the application.

Hello readers, in this blog. We are going to learn about the top git commands and their usage. Git is a free and open-source software for controlling the version of the application.

Why do we need GIT in Software Development?

  1. Git is a DevOps tool used to manage the source code.
  2. It is a tool which can be used to manage small to large scale products efficently. 
  3. Git is used to track the changes from different developers, working on the same time on one project.
  4. It makes management of code.
  5. Every developer can keep a track of there source code using there personal branches.
  6. Code merging is also very easy as each developer can raise a PR to check the code differences and merge the code.

In this tutorial blog we are going to use a sample source code to do all the changes. You can download the code Here - GitHub Link

 

Popular Files and Why they are used:

  1. Readme - The readme file is used to add instructions for the user on the process of how to install and set up the project. Inside the readme file, one can add images and commands to show things.
  2. Gitignore - Gitignore file is used to ignore the files while committing the project. Mostly files which carry sorry privates informations like aws key, server details etc are ignored for security purporses.
  3. Git Bash - Command Line tool to run 

How to add public key

To setup, an ssh key first run the command

ssh-keygen

after running this command find the file with name id_rsa.pub, copy the ssh key from there and add it inside github settings section.

Popular Commands in Git

Commands Usage
git init This is used to create a new repository. This creates a new GIT versioned project by initializing an empty repository
git config --list 

The git config list command will show all Git config properties throughout all of the variously scoped Git files.

git config --global user.name "mradul010" Git command is used to set the user.name of code uploader.
git config --global user.email "mradulmishra010@gmail.com" This is used to setup global email address for user
git remote --v It returns the base repository where you are working. If it comes null then you need to set a repository
git remote add origin git@github.com:codersdaily/GitLearning.git

This command simply means "you are adding the location of your remote repository where you wish to push/pull your files to/from !!.."

git remote set -url origin git@github.com:codersdaily/GitLearning.git This command simply means "you are adding the location of your remote repository where you wish to push/pull your files to/from !!.."
git pull Git pull copies all the files on git server repo to local repo with out looking for any difference. It mostly overwrites the existing local repo.
git fetch Git fetch only add the differences between the local repository and server repository.
git push This command is used to upload the code from local repository to server repository
git stash Git stash is a built-in command with the distributed Version control tool in Git that locally stores all the most recent changes in a workspace and resets the state of the workspace to the prior commit state.
git status The output of git status will usually say something about unmerged paths, or say that one or more files are both modified.
git add . It adds all the changes to be commited.
git commit -m "initial commit" It commits all the changes to the server.
git branch <branchname> It is used to change the branch
git checkout -b mradul-changes This is used to change the existing branch and copies the lastest code from the changed branch.

Add a comment:

Comments:

sekar

Great post! Git has truly revolutionized version control, making collaboration so much smoother. I particularly appreciate how Git branching allows for experimentation without risking the main codebase. For those looking to dive deeper, I've found that understanding Git's internal data structure—like how commits are stored as a chain—really helps in mastering more advanced features like rebasing. I've also written about some lesser-known Git tips that can streamline your workflow. Keep up the great work! <a href="https://codefrombasics.com/course/git-training-in-chennai">GIT Training in Chennai</a>