Skip to main content

Command Palette

Search for a command to run...

Practice GIT commands

Published
•3 min read•View as Markdown
Practice GIT commands

Introduction:

what is GIT?

Git is an version control system used to track all the changes in the codebase made by fellow developers.

so,before starting with git commands, Install Git by using sudo apt install git it will install new version of the git so after that check version of git installed on your computer git —version

git init initializes new repository in the current directory

All essential commands used in GIT:

1.Setup User:
use command git config --global user.name "Your Name" it sets the name that appears on Git commits
git config --global user.email "you@example.com" This sets email associated with your commits.
git config --global --list this command shows your details

git config --global user.name "Your Name" 
git config --global user.email "you@example.com"

git config --global --list

2. Basic commands to know:
Inorder to clone the opensourced projects use git clone <url> to get present working directory use
git status
To check all commit history use command git log

git clone <url>
git status 
git log

3. Staging and committing commands:
Git breaks the process into three types:
1.working tree
2. staging area
3. commit changes

so here git add . command helps to move changes to the staging area
“.“ used to move all the files at the same time and if any specific file need to move then use file name
git index.html after, use command git ststus to check which files are ready to commit the changes,
git commit -m “commit your changes“ This saves all the staging files in the github or gitlab

git add .
git index.html

git status

git commit -m “commit your changes“

4.Git Merging & Branching:
Git branching system is what makes it so powerful. It allows developers to work on different features or fixes independently without affecting the main code.
in order to create new branch use git branch feature-1 or git checkout -b feature-1
To switch between the branches use git checkout feature-1

After working on a feature in a branch xample feature-1 you usually want to bring those changes back into main and use git merge feature-1

git branch feature-1
git checkout -b feature-1 

git checkout feature-1

git merge feature-1

5.Remote Repositories
A remote repository is a version of your project hosted on the internet or a network usually on platforms like GitHub, GitLab.
use command git remote add origin https://github.com/yourusername/your-repo.git This adds remote named origin that points to github or gitlab reppositories
command git push -u origin main used to push the commited files to the gitlab
when ever need updated codebase use git pull origin main commnd
In order to clone a opensourced project to your computer use command

git remote add origin https://github.com/yourusername/your-repo.git
 git push -u origin main 
git pull origin main

git clone https://github.com/username/repo-name.git

most commonly used commands

echo "<h1> hello world!<h1>" >> index.html

git init

git add README.md

git commit -m "first commit"

git branch -M main

git remote add origin https://github.com/your-username/your-repo-name.git

git push -u origin main