Skip to main content

Command Palette

Search for a command to run...

Git Commit -m "Start learning git"

Basic & most useful commands to know about git..

Updated
โ€ข5 min read

Are Git and GitHub Same ?๐Ÿค”

Honestly, when I heard the names I thought they are synonyms but they are not ! Not even owned by the same company. So what are Git and GitHub exactly, and what is the difference between Git and GitHub as software tools and services?

Git is a free, high-quality distributed version control system suitable for tracking modifications in source code in software development. It was originally created as an open-source system for coordinating tasks among programmers, but today it is widely used to track changes in any set of files.

Github is It is a web-based Git repository. This hosting service has cloud-based storage. GitHub offers all distributed version control and source code management functionality of Git while adding its own features. It makes it easier to collaborate using Git.

README.md - The Magical Wand ๐Ÿช„

It's a special file that is widely used for the purpose of documentation. Even though you are not a programmer you can still understand what the project is about and kinda human-readable text is present in this file. It connects the user with the developer.

Pick up those pebbles ๐Ÿš

Installation ๐Ÿ“ฉ

Download Git From Here

While extracting the file leave the options as default or you can change them accordingly.

Git comes with the GitBash which is similar to the command prompt.

Now let's get started with the commands ๐Ÿ‘€ When you install the git. Firstly, you need to register yourself there. to do so -

git config --global user.name "Your Name"

git config --global user.email "youremail@yourdomain.com"

Now, to check you have successfully registered or not run-

git config --list

git init

This commit is used to initialize the git repository. The repository is a link or directory where you work on the projects.

git init

git add

3 basic parts of the git -

  • working directory (where you are currently working at)
  • Staging area
  • commits To understand it in a simpler way consider an analogy of taking the picture for the wedding album. The people standing in a queue are in working directory.

The one who are taking pictures with bride and groom on the stage are on staging area once they stand properly we capture the picture means pushing them from staging area to the final picture means our repository

Commits are the instructions that tells what and how to do something.

git add .

It adds all the files to the staging area.

git status

It tells the current scenario. what's going on in general.

git status

git commit

Pushes the files from the staging area to the repository.

git commit add -m "msg"

Tells history. what commits you made and all.

git log

VS code tips

VS code directly provides you the support to directly run git commands

g5.png

git remote

connect ur local project to GitHub repo

git remote add origin URL

git remote -v

git remote show

g1.png

git push

Push the changes to the GitHub repo.

git push origin master -u

git pull

sync changes of the remote repo to a local one

  1. Fetch the changes from the repo.

git fetch

  1. Merge your changes.

git merge origin/master

Combination of fetch and merge

git pull

git clone

It is used to make a copy off github repo and its content on your local machine.

git clone "repo URL"

GitHub Codespaces

It is the cloud-based environment for the VS code. GitHub Codespaces run on a variety of VM-based compute options hosted by GitHub.com, which you can configure from 2-core machines up to 32-core machines. You can connect to your codespaces from the browser or locally using Visual Studio Code.

git branch

The branch is your own directory you can work on..

git branch

rename branch

git branch -M main

Create new branch

git branch branchName

Delete a branch

git branch -d branchName

By using capital 'D'. It deletes the changes on master branch as well.

git branch -D branchName

Fork

It's a copy of someone else's project that you can work on. As you don't have any rights to change the original project you can make changes here and create a pull request(kind of permission). If that pull request gets accepted your changes will be merged to the original project.

Merge Conflicts

When you make any changes to the forked repo and on the same file and line someone else make the changes then the merge conflict arises as the git gets confused about which changes should be taken. They are handled inside the VS code editor inside the source control tool. Or you can use the following commands according to the need

Reset the changes you made. Don't use it if changes are pushed to the remote repo.

git reset

Reverts back to the changes

git revert

change the commit message of the committed commit.

git commit --amend

Save ur work for later without committing

git stash

git stash pop

git stash save pop post2

git stash list

Get this index using the git log command we learned earlier.

git stash apply index

Rebase

Rebase re-applies commits, one by one, in order, from your current branch onto another.An interesting option it accepts is --interactive (-i for short), which will open an editor with a list of the commits which are about to be changed.

git rebase master --interactive

g3.png

squash

Squashing a commit in Git means that you are taking the changes from one commit and adding them to the Parent Commit. Means binding them together.

git merge --squash

๐Ÿฒ ๐—š๐—ถ๐˜ ๐—ต๐—ฎ๐—ฐ๐—ธ๐˜€ ๐˜†๐—ผ๐˜‚ ๐˜€๐—ต๐—ผ๐˜‚๐—น๐—ฑ ๐—ฑ๐—ฒ๐—ณ๐—ถ๐—ป๐—ถ๐˜๐—ฒ๐—น๐˜† ๐—ธ๐—ป๐—ผ๐˜„.๐Ÿš€

Read this LinkedIn post made by my friend Om Gawande.

Kinda like a cheat sheet for the git commands that are rarely known but a hell lot useful.

References & resources to follow ๐Ÿ“’

O

Amazing one ๐Ÿคฉ Keep writing. ๐Ÿ“ˆ