DEV Community

Ragul Kannadasan
Ragul Kannadasan

Posted on

Git: Essential Commands

1.git init

Initializes a new, empty Git repository in your current directory. creates a hidden .git folder. This folder is the brain of your repository, storing all your tracking data, history, and branches.

git init
Enter fullscreen mode Exit fullscreen mode

2.git clone

Creates a local copy of an existing remote repository.Instead of starting from scratch, git clone downloads all the files, branches, and commit history from a remote server to your local machine.

git clone <repository_url>
Enter fullscreen mode Exit fullscreen mode

3.git status

Displays the state of your working directory.It won't change any files; it just tells you what is going on

git status
Enter fullscreen mode Exit fullscreen mode

4.git add

Adds modified or new files.You have to tell it exactly what you want to include in your next save. The staging area is like a loading dock. git add moves files.

add a specific file:

git add <file_name>
Enter fullscreen mode Exit fullscreen mode

add all changed files in the current directory:

git add .
Enter fullscreen mode Exit fullscreen mode

5.git commit

It acts as a permanent save point, capturing the state of files at a specific moment in time.

git commit -m "message here"
Enter fullscreen mode Exit fullscreen mode

6.git switch

Switches your working directory to a different branch.Once you create a branch, you have to move into it to start working.

git switch <branch_name>
Enter fullscreen mode Exit fullscreen mode

7.git merge

Combines the history of one branch into another.

git merge <branch_to_merge_in>
Enter fullscreen mode Exit fullscreen mode

8.git push

Uploads your local commits to a remote repository.Your local commits only exist on your computer. git push sends your saved milestones to the remote server (like GitLab and GitHub) so others can see and download your work.

git push origin <branch_name>
Enter fullscreen mode Exit fullscreen mode

9.git pull

Fetches and downloads content from a remote repository and immediately updates the local repository.

git pull origin <branch_name>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)