• About Us
  • Announce
  • Privacy Policy
  • Contact us
MasterTrend News
  • Home
    • BLOG
    • TECHNICAL SERVICE
    • STORE
  • Tutorials
  • Hardware
  • Gaming
  • Mobiles
  • Security
  • Windows
  • AI
  • Software
  • Networks
  • News
No result
See all results
  • Home
    • BLOG
    • TECHNICAL SERVICE
    • STORE
  • Tutorials
  • Hardware
  • Gaming
  • Mobiles
  • Security
  • Windows
  • AI
  • Software
  • Networks
  • News
No result
See all results
MasterTrend News
No result
See all results
Start Tutorials

10 Basic Git Commands Every Developer Needs 🖥️

MasterTrend Insights by MasterTrend Insights
April 3, 2025
in Tutorials
Reading time:Lectura de 7 minutos
TO TO
0
10 Basic Git Commands to Get You Started
1
SHARED
3
Views
Share on FacebookShare on Twitter

Contents

  1. 10 Basic Git Commands to Protect Your Code 🔒
  2. 1 Clone an Existing Repo
  3. 2 Create a New Repo
  4. 3 Create a Branch to Collaborate
  5. 4 Switch between Branches
  6. 5 Check Git Status
  7. 6 Commit Change Sets
  8. 7 Undo Changes
  9. 8 Upload All Your Local Changes
  10. 9 Recover All Changes
  11. 10 Merge It All Together
    1. Related Posts

10 Basic Git Commands to Protect Your Code 🔒

Spending another all-nighter trying to recover lost code changes? You're not alone. That's why millions of developers rely on Git, the world's leading version control system, to track every change and protect their work. Here's a rundown of the commands you'll use most. 🚀

If you're new to Git, let's start with a refresher. A Git repository (or repo for short) contains all of the project's files and the entire revision history. A repo has commits, which are used to record changes to the repo, and each commit has a short message that the user types to indicate what changes were made. Git can also help manage conflicts (for example, if two people edit the same line of code) before merging. To learn more about installing Git on Windows, click here.

1 Clone an Existing Repo

The first command we can start with is git clone, which is a command that connects and download a copy from an existing repository to your local machine. Usually, the existing repository is located remotely, such as on GitHub or GitLab.

First, go to a repo and click the green dropdown menu that says “Code,” then the copy to clipboard icon next to the GitHub repository URL, which will clone it using the Web URL. This is the easiest method and clones using HTTPS:

Number of arrows showing the option to clone repositories over HTTPS on GitHub.

Then, run the following command with the URL you just copied:

git clone https:
Repo clone completed message in Git Bash CLI.

Once the repo is cloned, you should have a local copy of it on your machine. 👍

If you get an error saying "fatal: repository not found," check the URL. If it's a private repo, you may need permissions to access it.

2 Create a New Repo

If you want to create a new Git repository instead of cloning an existing one, run git initThis initializes the repository in the specified directory, giving it a path. So it's ideal for new or untracked projects that you want to start using Git.

First, make sure you are in the correct folder before running the command:

git init
Empty repo error message in Git init commands.

3 Create a Branch to Collaborate

A branch in Git is a version of your repository, so multiple people can work on it simultaneously. In other words, it's an independent line of development within a repo. Typically, there are multiple branches in a repo.

To create a local branch, run the following command:

git branch branch-name

To list all your branches, run:

git branch

To delete a branch:

git branch -d branch-name
When you delete a branch, it is sometimes necessary to force the deletion. You just have to capitalize the -D, So: git branch -D branch-name

4 Switching between Branches

The command git checkout It is one of the most used, mainly to switch between branches, but it can also be used to review files and commits.

To switch between branches and check them out in your local directory:

git checkout branch-name

For newer versions of git, you can run:

git switch branch-name

For the above commands to work, the branch you are switching to must exist locally, and any changes to your current branch must be committed or saved first.

Shortcut command to create and switch branches at the same time: git checkout -b branch-name

5 Check Git Status

This is another common command, which can tell you different information about the current branch, such as whether the current branch is up to date or not, if there is anything left to commit or push, and if there are any files that were modified or deleted.

git status

This is what the output should look like if there are no changes to be made:

Git status command on the command line with output saying nothing to commit, clean working tree.

6 Commit Change Sets

This may be the most used Git command. When we're ready to save our work, perhaps after a specific task or issue, we can use git commitThis essentially captures a snapshot of the changes currently being prepared in the project.

You also need to write a short, clear commit message so you and other developers know about the changes. Don't forget to surround it with quotation marks.

git commit -m "confirmation message"
Git commit Just save your changes locally. You still need to push them to a remote repo.

7 Undo Changes

The command git revert allows you eliminate all the changes a single commit has made to your local repo. For example, if a previous commit added a file called ReadMe.md to the repo, a git revert In that commit, the ReadMe.md will be removed from the repo. A new commit will also be created to reflect this change.

All you need to do is run git revert followed by the commit ID:

git revert commit-id

If you've made a lot of commits and you're not sure where the commit ID is, you can identify the commit by running the command git log. Copy the commit ID and run the command git log with the commit ID.

Git log command in CLI showing previous commits and commit IDs.
Do not confuse git revert with git resetThe latter will undo every change that occurred since a given commit and change the commit's history. This isn't ideal if other people are working on the same branch.

8 Upload All Your Local Changes

Once you've finished making all your changes and committing them, you'll want to push your local changes to the remote repo. Pushing is the act of transferring these changes and commits from your local machine to the remote repository. You can specify which branch you want to send the changes to.

git push origin master

The above command pushes the changes to the master branch (master is usually considered the main branch, but "main" is also commonly used). If master doesn't work, try with main.

It is recommended to run git status before uploading your changes.

9 Recover All Changes

This is a command I use when I return to a project and need to retrieve all the new changes made to the master branch (whether through my merge or from other developers) that exist remotely. In other words, it's a command you use when you want to get updates from the remote repository.

git pull origin main

As before, yes master doesn't work, try with main. Since this command combines the functions of git fetch and git merge, instantly applies the latest modifications to your local repository (git merge) after retrieving updates from the remote repository (git fetch). You can learn more about pull requests in Git.

10 Merge It All Together

Finally, once you're done working on your branch and everything is working correctly, the last step is to merge the branch into the main branch (usually dev or master, but check the repo).

You can do this by running the command git merge. First you should execute git fetch to update your branch local, and then make your merge:

git merge branch-name
Make sure you are on the branch you want to merge into your remote master branch.

In the end, learning Git is like riding a bike: once you start, it only gets easier with every push! 🚴‍♂️💻

Share this:
FacebookLinkedInPinterestXRedditTumblrBlueskyThreadsShare

Related Posts

  • How to Fix Messenger on Windows 11 Fast! ⚡
  • Restart your device 🔄 Eliminate errors in minutes!
  • How to build a gaming PC
  • How to Format a USB Drive on Windows and Mac: Quick Fix ⚡🔌
  • Intel Alder Lake P and U aspects
  • Microsoft Edge crashes on Windows
  • Guide to Accessing Location History on Your iPhone
  • Bell-1 Quantum Computer: A Revolutionary Innovation! 💻✨
Tags: Evergreen ContentTechTipsWindowsTips
Previous Post

AI Features in Chrome 🔥: Transform Your Browsing

Next publication

Kernel Verification Failures: Fix It Now! 🔥

MasterTrend Insights

MasterTrend Insights

Our editorial team shares in-depth reviews, tutorials, and recommendations to help you get the most out of your digital devices and tools.

Next publication
BSOD 'Kernel Security Check Error' 😱. Find out how to fix it quickly and easily in just a few minutes.

Kernel Verification Failures: Fix It Now! 🔥

5 3 votes
Article Rating
Subscribe
Access
Notify of
guest
guest
0 Comments
Oldest
Newest Most voted
Online Comments
See all comments

Stay Connected

  • 976 Fans
  • 118 Followers
  • 1.4k Followers
  • 1.8k Subscribers
Subscription Form
  • Tendencies
  • Comments
  • Last
How to add a clock to the Windows 11 desktop: 3 surefire tricks!

How to add a clock to your Windows 11 desktop: Get more done in minutes! ⏱️

May 1, 2025
12 Best Alternatives to Lucky Patcher for Android

Lucky Patcher Alternatives: 12 Better and Easy Apps! 🎮⚡

May 12, 2025
How to use AdGuard DNS on Android in 2024

How to use AdGuard DNS on Android in 2025

February 11, 2025
How to Store Items in Oblivion Remastered: 5 Tricks You Need to Know! 🗝️💼

How to store items in Oblivion Remastered without losing your loot 💎⚡

May 1, 2025
Gmail Features on Android: Save Time with 5 Tips

Gmail Features on Android: 5 Tricks You Didn't Know About! 📱✨

12
Motherboard repair - Repair Motherboards

Notebook Motherboard Repair

10
Install Windows 11 Home without Internet

Install Windows 11 Home without Internet

10
How to Back Up Drivers in Windows 11/10 in 4 Steps!

How to Back Up Drivers in Windows 11/10: Avoid Errors! 🚨💾

10
Steam Deck: Multiply your library with Heroic in 5 easy steps

Steam Deck: Multiply your library with Heroic in 5 easy steps 💥💻

June 25, 2025
HDMI 2.2 🚀: Double speed for 16K video and ultra-realistic gaming! 🎮✨

HDMI 2.2 🚀: Double speed for 16K video and ultra-realistic gaming! 🎮✨

June 25, 2025
Random Usernames Protect your account today

Random usernames: The key to avoiding mass hacks 🛡️🚫

June 25, 2025
Unlock Yasuke Discover the secret Kofun that will change your game!

Unlock Yasuke: Discover the secret Kofun that will make you dominate! 🥷💥

June 25, 2025

Recent News

Steam Deck: Multiply your library with Heroic in 5 easy steps

Steam Deck: Multiply your library with Heroic in 5 easy steps 💥💻

June 25, 2025
12
HDMI 2.2 🚀: Double speed for 16K video and ultra-realistic gaming! 🎮✨

HDMI 2.2 🚀: Double speed for 16K video and ultra-realistic gaming! 🎮✨

June 25, 2025
3
Random Usernames Protect your account today

Random usernames: The key to avoiding mass hacks 🛡️🚫

June 25, 2025
9
Unlock Yasuke Discover the secret Kofun that will change your game!

Unlock Yasuke: Discover the secret Kofun that will make you dominate! 🥷💥

June 25, 2025
12
MasterTrend News logo

MasterTrend Info is your go-to source for technology: discover news, tutorials, and analysis on hardware, software, gaming, mobile devices, and artificial intelligence. Subscribe to our newsletter and don't miss any trends.

Follow us

Browse by Category

  • Gaming
  • Hardware
  • AI
  • Mobiles
  • News
  • Networks
  • Security
  • Software
  • Tutorials
  • Windows

Recent News

Steam Deck: Multiply your library with Heroic in 5 easy steps

Steam Deck: Multiply your library with Heroic in 5 easy steps 💥💻

June 25, 2025
HDMI 2.2 🚀: Double speed for 16K video and ultra-realistic gaming! 🎮✨

HDMI 2.2 🚀: Double speed for 16K video and ultra-realistic gaming! 🎮✨

June 25, 2025
  • About Us
  • Announce
  • Privacy Policy
  • Contact us

Copyright © 2025 https://mastertrend.info/ - All rights reserved. All trademarks are property of their respective owners.

es_ES Spanish
es_ES Spanish
en_US English
pt_BR Portuguese
fr_FR French
it_IT Italian
ru_RU Russian
de_DE German
zh_CN Chinese
ko_KR Korean
ja Japanese
th Thai
hi_IN Hindi
ar Arabic
tr_TR Turkish
pl_PL Polish
id_ID Indonesian
No result
See all results
  • Gaming
  • Hardware
  • AI
  • Mobiles
  • News
  • Networks
  • Security
  • Software
  • Tutorials
  • Windows

Copyright © 2025 https://mastertrend.info/ - All rights reserved. All trademarks are property of their respective owners.

Comment Author Info
:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
wpDiscuz
RedditBlueskyXMastodonHacker News
Share this:
MastodonVKWhatsAppTelegramSMSHacker NewsLineMessenger
Your Mastodon Instance