DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Mastering Git
  • Developer Git Commit Hygiene
  • A Comprehensive Guide to GitHub
  • Understanding Git

Trending

  • Navigating Double and Triple Extortion Tactics
  • Simplifying Multi-LLM Integration With KubeMQ
  • Designing for Sustainability: The Rise of Green Software
  • What Is Plagiarism? How to Avoid It and Cite Sources
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Simple CRUD With Git

Simple CRUD With Git

Learn to use some of the basic CRUD commands in Git, like creating a repo and adding or deleting files, to make your life easier and improve productivity.

By 
Unni Mana user avatar
Unni Mana
·
Sep. 19, 17 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
9.2K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, I will show you how to perform basic operations with Git that will improve the productivity of a developer. Git is an essential tool to learn and master, as many projects depend on it. This article will show some of the basic operations that come handy in day to day life while dealing with Git.

Create a Repository

The first thing we need to do is to create a remote repository on github.com. For that, you need to log into github.com. After a successful login, you need to create a repository called "test" using the "create a repository" button. This is the repository we are going to work with.

Add New Files

By default, the repository is empty except for a README.MD file.

In order to add a new file, first you need to clone this "test" repository to your local disk. In order to do that, run the following command:

git clone https://github.com/unnivm/test.git

This will download and create a folder called "test" on your local disk. If there are any files in it, all of them will be downloaded into the "test" folder.

Now add a new file called "test.txt" with some contents in it under the "test" folder. Then run the following command:

git add .

The above command will add the new files to your repository.

The next command is to commit this new file.

git commit -m "this is my first file"

The -m switch is the message that you want when you commit the changes.

Now we need to send this change to the remote repository. For that, run the following command.

git push origin master

This command will lead to authenticate the user once again and send your file to new repository.

Let us take a look at the above command in detail:

  • push - Sends the files or changes to remote repository.

  • origin - The default name of the repository given by Git. 

  • master - The default branch name in the repository. This is where all your changes will be pushed into unless a different branch name is mentioned.

Update Files

Now you are going to modify the files you created in the above step. Let us modify the "test.txt" file we created in the above step. We need to perform the following operations one by one:

git add .
git commit -m "I have modified my file"
git push origin master

Once you execute the above commands one after another, your files will be updated in the git remote repository.

Delete Files

Now we want to delete either a single file or multiple files from the remote repository. In order to do this, issue the following commands:

git rm <name of your file>
git commit -m "the file has been deleted"
git push origin master

These commands will help you in delete the file in your git repository as well as from your local file system.

In order to delete multiple files, you need to mention the files to be deleted. For example, if you want to delete 2 files, namely, file1.txt and file2.txt, then issue the following command:

git rm file1.txt file2.txt

Summary

We have seen the minimal necessary commands while working with a Git repository. In all the CRUD operations which we have seen, the following commands are mandatory:

git commit -m "your commit message"
git push origin master

You can do much more with Git, but this article is just beginner level for anyone to understand the basic concepts of Git. 

Git Repository (version control) Command (computing)

Opinions expressed by DZone contributors are their own.

Related

  • Mastering Git
  • Developer Git Commit Hygiene
  • A Comprehensive Guide to GitHub
  • Understanding Git

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!