The Wayback Machine - https://web.archive.org/web/20240824142502/https://www.geeksforgeeks.org/basic-git-commands-with-examples/
Open In App

Basic Git Commands with Examples

Last Updated : 11 Feb, 2021
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Nowadays open source contribution is on the peak. It’s getting so much popular among students and there are also some open-source programs and competitions to learn so much about development. Open source is a great way to learn and make a better community. There are so many organizations where one can contribute and learn. For that one have to know about using git commands. As a complete beginner, It might be a little difficult for someone to learn a huge number of git commands. So here is the solution. Below, you can get 6 simple git commands with that you can start open-source contributions in any organization. 

cd <file path> command

First, you have to create a file where your code will be stored on your pc. For that, you have to create a file on your desktop. After that open Git Bash and type cd <File directory> to go to file and branch.

git clone command

If you want to open-source contribution. First, you have to copy an existing repository (the repository, where you want to contribute) on your local repository (Your repository). For that, you have to click the fork button on the repo of the existing repository on GitHub. 

  • What is forking: Forking any repository means make a copy of a real repository in your GitHub account and make changes in your copy. Thus, a real repository won’t get affected by your code changes. (After that you have to make a pull request to the real repository for merging your code change, we will come to that part later)
  • How to do fork: Just go to the real repo and tap on the fork button

  • Copy URL: Then a copy of real repository will be created in your local repository. After that, you have to copy the URL from your local repo. For doing that click to code and copy the URL.

  • After that, you have to create a file on your desktop. Then open Git Bash and go to the file using cd command and click enter and type git clone <copied url> to copy the code in your desktop file. With that, you are able to get the code on your desktop.

git status command

After making code changes you have to add the files for that you have to check which files are not added. For that use git status. The command git status can show you the status of your current file whether it is added or committed or pushed. 

git add <File name> command

When you get to know which files are not added by typing git status(red-colored files are not added). Then type git add <file name> to add files.

git commit -m <message> or git commit -am<message> command

After that, you have to commit those added files (type git status to check status, and green colored files are not yet committed). Type git commit -m <message> (message is nothing but a text that tells about what is changed in files) (there are many types of commit command you can check out git documentation in git official website). 

git push command

At last, you have to push your code changes in your local repo by typing git push and then make a pull request.

  • How to make a pull request: After pushing your code to your local repository you have to make a pull request to merge your code to the real repository. To do that just go to your local repo and click on the pull request.


Previous Article
Next Article

Similar Reads

Useful Git Commands and Basic Concepts
Git is a powerful version control system widely used in software development to track changes, collaborate on projects, and manage code efficiently. Understanding the basic concepts and commands in Git is important for any developer. This article will cover the fundamental concepts and some of the most Useful Git Commands and Basic Concepts to help
5 min read
Difference Between Git remote prune, Git prune and Git fetch --prune
Git is a version control system that helps developers manage and track changes in their codebase. Among its many commands, git remote prune, git prune, and git fetch --prune are essential for maintaining a clean and organized repository. This article will explain the differences between these commands, their syntax, uses, and provide examples to il
4 min read
Simple and Concise Git Commands That Every Software Developer Should know
As developer git is the most useful arena which is not operated directly so do we have git commands that become very crucial that one should know after having git installed in the local system. if not you must download git from here Download Git. If you need any help with the further installation process. So, Now let's start with the basic commands
4 min read
Essential Git Commands
When it comes to commands, there come numerous commands in a software developer head or one that is mastering over git but even only a few of them are used frequently in the enterprising domains that are used frequently by developers in order to boost workflow. So here we will be listing a couple of them prior to dividing them into categories in or
3 min read
How to Use Git Commands in Android Studio Terminal?
Android Studio is the official IDE (Integrated Development Environment) for Android app development and it is based on JetBrains’ IntelliJ IDEA software. Git is a Distributed Version Control System. It is used in Software Development. Git was developed by Linus Torvalds in the year 2005 to manage the development of the Linux Kernel Need of Git Git
2 min read
How to Push Folders From Local PC to GitHub using Git Commands?
Git offers a powerful command-line interface for managing code repositories, understanding how to push folders from your local PC to GitHub repositories using Git commands can enhance your workflow and streamline the process of sharing code with collaborators or deploying projects. In this article, we'll see the step-by-step process of pushing fold
2 min read
All Git Commands You Should Know
Git is a distributed version control system (VCS) that allows multiple developers to work on a project at a time, giving the possibility of changing each other's work based on requests and authorizations. Created by Linus Torvalds in 2005 for the development of the Linux kernel, Git has since become the most widely used version control system in th
8 min read
How to Dry Run Git Commands?
Git is used for version control in software development. Understanding the effects of Git commands before executing them can help prevent mistakes and ensure that your repository remains in a good state. This is where "dry running" Git commands become incredibly useful. A dry run simulates the execution of a command without making any changes, allo
3 min read
Top 15 Git Commands to Become a Pro Developer [2024]
Git is a distributed version control system and open-source software used by developers to manage different versions of source code by tracking changes in files. It is used by developers to work together on the same project from anywhere. Whether you are a professional developer or just starting your coding journey, Git is essential for becoming a
8 min read
How to Generate Public SSH or GPG Keys Using Git Commands?
Generating public SSH or GPG keys is important for securing your Git operations and ensuring the authenticity of your commits. In this guide, we'll walk you through the process of generating these keys using Git commands, making it easy to track along and understand. What Are SSH Keys?SSH (Secure Shell) keys are a pair of cryptographic keys used to
2 min read
How to Use Git Shell Commands?
Git is a powerful version control system that is important for managing source code in modern software development. While there are many graphical user interfaces (GUIs) available for Git, mastering Git shell commands can significantly enhance your productivity and control over your repositories. This article provides an overview of essential Git s
3 min read
Top 12 Git Commands for Every Developer
Git is a distributed version control system and open-source software. It enables developers to manage many versions of a source code with ease. You can use it to figure out who did what, when, and why. Git has become a must-have tool for any developer nowadays, and knowing Git commands is required for developers to fully utilize Git. There are hund
9 min read
Git - git-show Command Line Utility
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git relies on the basis of distributed development of software where more than one developer may have access to the source code of a specific application and can modify changes to it that may be
3 min read
Git LFS: Managing Large Files in Git Repositories
Git, undoubtedly one of the most popular version control systems, is widely used for managing source code in software development projects. However, one of its limitations is its handling of large files. Traditional Git repositories struggle to efficiently manage large files, leading to bloated repositories and slow performance. This is where Git L
4 min read
Git Subtree vs. Git Submodule
Git Subtree and Git Submodule are both mechanisms in Git that allow you to incorporate external repositories into your own repository. They provide a way to manage dependencies and include code from other projects while keeping your repository organized and maintainable. Git Subtree: Git Subtree allows you to insert a separate repository as a subdi
4 min read
Difference Between Git Fetch and Git Pull
Understanding the difference between git fetch and git pull is important for effective version control in Git. These commands are important for managing your repository and collaborating with team members. In this article, Let us look at Git Fetch and Git Pull separately with the help of an example. What is Git Fetch?The Git Fetch command is used t
4 min read
Difference Between Git Push Origin and Git Push Origin Master
Understanding the difference between git push origin and git push origin master is important for efficient version control in Git. These commands are used to upload changes from your local repository to a remote repository, but they function differently. This article will explain these differences, how each command works, and when to use them. What
3 min read
How to Set Up Git Using Git Config?
Git is a powerful version control system that helps developers manage and track changes in their code. Setting up Git correctly is important for maintaining an organized and efficient workflow. In this article, we'll walk you through the process of setting up Git using the git config command. PrerequisitesBefore we dive into the setup process, make
3 min read
How To Exit Git Log or Git Diff?
When working with Git, the git log and git diff commands are important for viewing commit history and changes between commits, respectively. However, if you're new to Git, you might find yourself stuck in these views, unsure how to exit. This article will guide you through the steps to exit git log or git diff, ensuring a smooth experience while na
2 min read
Git - git prune
Git is a powerful version control system that helps developers manage their code efficiently. However, as your project evolves, you may accumulate unnecessary data that clutters your repository. This is where git prune comes in view. What is git prune?git prune is a Git command that removes objects that are no longer referenced by any branch or tag
5 min read
Difference between “git add -A” and “git add”
When working with Git, the git add command is used to move changes from your working directory to the staging area. However, there are different options and flags that can be used with git add, such as -A, which might lead to some confusion. In this article, we'll explore the differences between git add -A and git add. 1. Git add- CommandThe git ad
2 min read
Git - Difference Between Git Revert, Checkout and Reset
Git offers a range of commands to manage and manipulate your codebase. Among these commands, git revert, git checkout, and git reset are frequently used for different purposes. Understanding the differences between these commands is important for effective version control. In this article, we'll explore the functionalities and use cases of git reve
6 min read
How to Fix Git Error "Unable to create '/path/my_project/.git/index.lock'"?
The Git error "Unable to create '/path/my_project/.git/index.lock'" typically occurs when Git is unable to create or write to the index.lock file. This file is used to prevent simultaneous processes from modifying the repository, which could lead to corruption. Table of Content Remove the Lock File ManuallyUse Git Command to Remove the Lock FileRes
2 min read
Difference Between "git commit" and "git push"?
Git commit and git push are two essential commands you'll use a lot when working with Git. even their frequent use together, they have different functions. In order to help you understand when and how to use these two commands effectively in your version control workflow, this article will break down their differences. What is git commit?git commit
2 min read
Git Features
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git relies on the basis of distributed development of software where more than one developer may have access to the source code of a specific application and can modify changes to it which may b
9 min read
Bare Repositories in Git
Repositories in Git are a snapshot of the folder in which you are working on your project. You can track the progress and changes made to the project by making commits and also revert changes if not satisfactory. Repositories can be divided into two types based on the usage on a server. These are: Non-bare Repositories Bare Repositories What is a N
7 min read
Getting changes from a Git Repository
Git allows performing various operations on the Repositories including the local repositories and remote repositories. The user when downloads a project to work upon, a local repository is created to store a copy of the original project. This local repository stores the changes that are being made by the user. This way, the user can edit the change
4 min read
Git | Working with Stash
Pre-requisites: Git Git allows multiple users to work on the same project simultaneously. Suppose a developer is working on a feature in a branch and he needs to pull changes from some other developer's branch or if he has to work urgently on some other feature, but the feature he is currently working on is incomplete. In this case, you cannot comm
8 min read
Handling repositories with Git remote
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Syncing ability of the git allows the developers to access and work on any project anytime anywhere. The collaboration among developers via git takes place when git provides each individual deve
4 min read
Using Git on CommandLine
Git is very important and powerful tool when it comes to the software development life cycle. Now in this article, we are going to see why git is used vastly in the software industry and what kinds of operations we can perform with git. So git is basically a distributed version control system for tracking changes in source code during software deve
5 min read
Article Tags :
three90RightbarBannerImg