Git Basic Commands Introduction

Git Basic Commands Introduction

Git is a distributed version control system that enables multiple developers to work together on a single project. It is a valuable tool in software development and has become an essential skill for developers. This article will introduce some commonly used Git commands. If you are a new user or not familiar with Git, this article is an excellent starting point for you.

Setup

Before you can use Git, you need to set it up on your computer. You can download and install Git from the official website. After installation, you need to configure Git with your name and email address, so Git can properly track your changes.

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

Creating a Git Repository

Once Git is set up, you can create a new Git repository. A repository is basically a folder where all your project files are stored. To create a new Git repository, navigate to the folder where you want to store your project files and run the following command:

git init

This command initializes a new Git repository in your current folder.

Adding Files

After you have created a Git repository, you can add files to it. To add a file to Git, use the following command:

git add filename

This command adds a specific file to the Git repository. If you want to add all the files in the current folder to the Git repository, use the following command:

git add .

Committing Changes

After you have made changes to your files, you need to commit those changes to the Git repository. To do this, use the following command:

git commit -m "commit message"

This command creates a new commit in the Git repository with the provided commit message.

Viewing the Status

To view the status of your files in the Git repository, use the following command:

git status

This command shows which files have been modified or added and which files are currently staged for the next commit.

Viewing the Commit History

To view the commit history of your Git repository, use the following command:

git log

This command shows a list of all the commits in the Git repository.

Branching

A branch is a separate copy of your project’s files. You can create a new branch to work on new features or bug fixes without affecting the original branch. To create a new branch, use the following command:

git branch branchname

This command creates a new branch with the provided branch name. To switch to the new branch, use the following command:

git checkout branchname

You can also create and switch to a new branch in a single command:

git checkout -b branchname

Merging

Once you have completed your work on a branch, you can merge your changes back into the original branch. To do this, switch to the original branch and use the following command:

git merge branchname

This command merges the changes from the specified branch into the current branch.

Cloning a Repository

To clone an existing Git repository, use the following command:

git clone repositoryurl

This command creates a copy of the Git repository in a new folder on your computer.

Pushing Changes

After you have made changes to your repository, you can push those changes to a remote repository. To do this, use the following command:

git push remotename branchname

This command pushes the changes in the specified branch to the specified remote repository.

Conclusion

This article has provided an overview of some commonly used Git commands. Git is a powerful tool that enables multiple developers to work together on a single project. By learning these basic commands, you can get started with Git and begin collaborating with other developers on your projects.

Like(1)

Related

Git Tutorials
Git TutorialDifferences between Git and SVNGit vs. Github: What's the Difference?How to Install Git on WindowsHow to Install Git on LinuxHow to Install Git on MacConfiguring Git on Your Local EnvironmentGit Workflow Detailed ExplanationGit Basic Commands IntroductionGit add command detailed explanationGit amend Command: A Comprehensive GuideA comprehensive guide to Git apply commandGit branch Command: A Comprehensive GuideGit Blame command: A detailed explanationGit Config Command in DetailGit clone Command: A Detailed ExplanationA Comprehensive Guide to the Git Clean CommandUnderstanding and Using Git Commit CommandA Comprehensive Guide to Git Checkout commandGit cherry-pick Command: A Comprehensive Guide to Its UsageA Detailed Guide to Git Diff CommandGit Fetch Command: A Comprehensive GuideA Comprehensive Guide to Git Format-Patch CommandGit ignore Command: A Detailed GuideGit init Command: A Comprehensive GuideA Comprehensive Guide to Using Git Log CommandGit merge command tutorialA Comprehensive Guide to Using Git mv CommandGit push command: A Detailed Guide on Using itA Comprehensive Guide to Using Git Pull CommandGit remote command usageGit Revert Command Detailed ExplanationGit reset Command: A Comprehensive GuideGit Restore Command: A Comprehensive GuideA Comprehensive Guide to Git Rebase CommandGit reflog Command Usage ExplainedGit rm Command Usage OverviewGit Status Command - A Detailed GuideDetailed Explanation of Git Stash CommandGit show Command: An In-depth GuideGit Switch Command: A Comprehensive GuideComplete Guide to Using Git Tag CommandGit .gitignore File: A Comprehensive Guide