DEV Community

Rutvik Patel
Rutvik Patel

Posted on • Edited on • Originally published at rutikkpatel.Medium

Basic Git Commands

Basic Git Commands

Git is a super-powerful version control system that allows its user or developers to track changes in written code and do a collaboration with others on software projects. Whether you are a beginner or an experienced developer, understanding the basics of Git commands is essential for using Git effectively. In this article, we will explore six fundamental Git commands that you need to know to get started with version control.

Created By [Author](https://medium.com/@rutikkpatel) ( [Rutik Patel](https://medium.com/@rutikkpatel) )

By the end of this article, you will have a good understanding of how to use these Git commands to manage your code changes and collaborate with other developers. So let’s dive into the world of Git and explore these basic Git commands in detail.

 

Index

  1. git clone

  2. git init

  3. git add

  4. git commit

  5. git push

  6. git remote


1. git clone

If you want a local copy of a repository from GitHub, this command allows creating a local copy of that repository on your local directory from the
repository URL.

git clone remote-repository-url
Enter fullscreen mode Exit fullscreen mode

You can find the remote repository URL by clicking on the code button with green background in any git repository, as shown in the example below.

[My GitHub repository](https://github.com/rutikkpatel/Cocoon-Gem-Rails)

 

2. git init

the git init command will create a new local repository.

git init
Enter fullscreen mode Exit fullscreen mode

Apart from it, you can create a repository within any folder by specifying the project name:

git init MyProject
Enter fullscreen mode Exit fullscreen mode

 

3. git add

git add is used to add files to the staging area and for removing file from the staging area you can use the same command.

git add FileName
Enter fullscreen mode Exit fullscreen mode

To add all the files of the local repo.

git add -A
Enter fullscreen mode Exit fullscreen mode

Another command for the same is,

git add .
Enter fullscreen mode Exit fullscreen mode

Note → The command git add . only stages files in the current folder and not any sub-folders, however, git add -A will stage all available files in sub-folders too.

To add only specific files and folders.

git add FolderName/FileName
Enter fullscreen mode Exit fullscreen mode

 

4. git commit

git commit will create a snapshot of the changes and save it to the git directory.

git commit -m "Any Message Here"
Enter fullscreen mode Exit fullscreen mode

The message in the commit command is nothing but a text that tells about what is changed in files.

Example → git commit -m "fix: user profile is not showing on the about us page"

 

5. git push

git push command is used to push or send local commits to any branch of the remote git repository. Here’s the basic code structure

git push origin BranchName
Enter fullscreen mode Exit fullscreen mode

Replace BranchName with your branch name in which you want to push the changes.

Example → git push origin feature-contact-us-page

 

6. git remote

git remote lets you view all remote repositories also used to connect your local repository to the remote server and List all connections along with their URLs.

To list the remote connections

git remote
Enter fullscreen mode Exit fullscreen mode

List the remote connections with URL :

git remote -v
Enter fullscreen mode Exit fullscreen mode

To connect the local repository to a remote server.

git remote add origin RepositoryURL
Enter fullscreen mode Exit fullscreen mode

To remove a connection of a folder or file to a particular remote repository

git remote rm RepositoryName
Enter fullscreen mode Exit fullscreen mode

Top comments (0)