GIT Crash Course

GIT Crash Course

ยท

4 min read

WHAT IS GIT?

Git is a free, open-source distributed version control software that lets you manage and keep track of your source code history. It was created by Linus Torvalds in 2005. This tool is a version control system that was initially developed to work with several developers on the Linux kernel.

You can download git for your Mac/Windows/Linux at git-scm.com/download.


SOME BASIC TERMS:-

  • repository keeps all your project's files, including commits and branches.

  • branch is a copy of the repository holding the specific version. The main branch in git is master.

  • commit is a command used to save changes to the specific branch or repository.

  • fork is a copy of the repository.

  • checkout is the operation of switching between the current branch and the one specified in the command.

  • master is the main branch of the repository.

  • merge is an action that adds changes from one branch to another.

  • head is the most recent commit of the repository you working with.


BASIC GIT COMMANDS

Let's have a look at some of the basic git commands:-

GIT CONFIG

$ git config --global user.name "username"
$ git config --global user.email "user@email.com"

git-config.PNG

this command is used to set the current user name and email configuration to be used in commits.

GIT INIT

$ git init

git-init.PNG

this command is used to initialize an empty repository from the folder you are currently using this command.

GIT STATUS

$ git status

git-status.PNG

this command is used to check the status of the modified files and it shows which files are staged, unstaged, and untracked.

GIT ADD

$ git add "file name"

git-add-file.PNG

this command adds a file to the staging area

$ git add .

git-add-2.PNG

this command adds all the files to the staging area.

GIT COMMIT

$ git commit -m "commit message"

git-commit.PNG

This command is used to commit all staged changes with the custom message passed as a string. It saves file changes permanently in the version history.

If you want to push those changes to github, then you've to create a new repository ๐Ÿงก 3.PNG 4.PNG 5.PNG

GIT REMOTE

$ git remote add

git-remote.PNG

this command is used to connect your local repository to the remote server

GIT PUSH

$ git push -u origin master

git-push.PNG

this command sends the committed changes of the master branch of your remote repository.

git-push-2.PNG

GIT LOG

$ git log

git-log.PNG

this command is used to list the version history for the current branch

GIT CLONE

git clone "repository-URL"

github-clone.PNG

git-clone.PNG

this command is used to copy or clone the existing repository to the specified folder on your computer.

GIT PULL

$ git pull

git-pull.PNG

this command fetches and merges changes on the remotes server to your local working repository.

GIT FETCH

$ git fetch

git-fetch.PNG

this command retrieves the most recent changes from the origin branch but doesn't merge.

GIT BRANCH

$ git branch

this command lists out all the branches in the repository.

$ git branch "branchname"

git-branch.PNG

this command creates a new branch

$ git branch -d "branchname"

git-delete-branch.PNG

this command will delete the branch with the specified branch name.

GIT CHECKOUT

$ git checkout "branch-name"

this command is used to switch from one branch to another

$ git checkout -b "branch-name"

git-checkout-branch.PNG

this command creates a new branch and also switches (checkout) to it.

GIT MERGE

$ git merge "branchname"

git-merge.PNG

this command merges the branch with the specified branch to the current branch.

GIT REVERT

$ git revert "commit-hash"

this command creates a new commit that undoes changes made in the specified commit and applies it to the current branch.

GIT RESET

$ git reset "filename"

git-reset.PNG

It remotes specifies a file from the staging and leaves the working directory unchanged.

$ git reset --hard "commit"

this command discards all history and goes back to the specified commit


Resources:-


NOTE:- I'll keep updating this article with time & looking to make it more beginners friendly

ย