Git

Pradeep Sharma
3 min readFeb 19, 2023

In this post will learn about Git and its uses

first of all to understand Git we have to know….

What is Git?

Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

as we get to know git is a version control system the question arises What is “version control”, and why should you care?

Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.

Local Version Control Systems

Many people’s version-control method of choice is to copy files into another directory (perhaps a time-stamped directory, if they’re clever). This approach is very common because it is so simple, but it is also incredibly error-prone. It is easy to forget which directory you’re in and accidentally write to the wrong file or copy over files you don’t mean to.

To deal with this issue, programmers long ago developed local VCSs that had a simple database that kept all the changes to files under revision control.

Distributed Version Control Systems

This is where Distributed Version Control Systems (DVCSs) step in. In a DVCS (such as Git, Mercurial, Bazaar or Darcs), clients don’t just check out the latest snapshot of the files; rather, they fully mirror the repository, including its full history. Thus, if any server dies, and these systems were collaborating via that server, any of the client repositories can be copied back up to the server to restore it. Every clone is really a full backup of all the data.

here I Mention some of the commands for git.

  1. Set user name: —
    git config — global user.name name
  2. 2- Set email:-
    git config — global user.email Email Id

3- Add files in the staging area individually:-
git add fileName

4- Add all files to the staging area at a time:-
git add -A

5- To know file names that are in the staging area/added.

git status

6- To commit files:-

git commit -m “message of commits”

7- To get the updated code of a particular file
git checkout fileName

8- To get updated code of multiple(all) files at a time.

git checkout -f

9- To see the last numbers of commit

git log -p -number

10- To compare code with a working area to a staging area.
git diff

11- To delete a file from the working directory and also from the staging area

Git rm fileName

12- To delete files only from the staging area

Git rm -cached fileName

13- To know the sort status of the working directory and staging area.

Git status -s

14- To create ignore file

Touch .gitignore

15- To create a new branch and switch to the same branch
Git checkout -b branchname

16- To switch branch
Git checkout branchName

17- To get Updated code from the branch
Git pull origin branchName

18- To merge specific branch

Git merge branchName

19- To push code on repo

Git push origin branchName

20- get pull from a specific branch in git

Git pull [remote name] [branch name]

Thanks for reading the blog Happy Coding!!!

--

--