Git Basics for Newbies: Key Commands to Know
In this article we are going to explore the commands that ypu should must know before starting to work with git although vs code provides a GUI at the side bar for doing all the basics stuff but we are developers , we don’t do any thing with the GUI we need to look like hackers and you know what using terminal commands and seeing the changes and commits in the terminal kind of serves that purpose so lets dive into the basic commands of git and remember this are not all the commands that you will need to know in git but being in industry for more that 2 years as of publishing date of this blog I will cover all the commands that you will be using 90% of time in Git so lets dive in ….
Getting Started and Setup
git config: Configures user information and settings for Git. You should set your name and email globally the first time you use Git.git config --globaluser.name"Your Name"git config --globaluser.email"your.email@example.com"
git init: Initializes a new Git repository in the current directory, creating a hidden.gitfolder to track changes.git clone [url]: Creates a local copy of an existing remote repository, including all files, history, and branches.
The Basic Workflow: Save and Sync Changes
This sequence is the most common workflow for saving your work:
git status: Checks the status of your working directory and staging area, showing which files are modified, staged, or untracked. Run this frequently to understand where your changes are.git add: Stages changes for the next commit.git add <file>to stage a specific file.git add .to stage all new and modified files in the current directory and subdirectories.
git commit: Records the staged changes as a snapshot in the local repository's history. The-mflag lets you add a descriptive message inline.git commit -m "A descriptive message of your changes"
git push: Uploads your local commits to a remote repository (e.g., GitHub, Bitbucket).git push origin mainsends commits from your localmainbranch to theoriginremote.
git pull: Fetches changes from the remote repository and merges them into your current local branch, keeping your local copy in sync with the team's work.
Branching and Merging
Branches allow you to work on new features or fixes in isolation from the main codebase.
git branch: Lists all local branches in your repository.git branch <name>: Creates a new branch with the specified name.git switch <name>(orgit checkout <name>): Switches you to a different branch to start working on it.git merge <branch>: Integrates changes from a specified branch into your current active branch.
Other Useful Commands
git log: Displays the commit history for the current branch, helping you review past work.git diff: Shows the differences between changes in your working directory, staging area, or between commits.git stash: Temporarily shelves changes you've made in your working directory when you need to switch contexts but aren't ready to commit.
So with this we cover almost all the most important commands although there are many more commands such as git rebase (Dont try doing it too much in large projects it will turn you mad) and git reflog but that commands we will discuss in other blogs for now if you just master this above commands you are good to go…
To know more about git you can refer to this article-https://blogs.arnabsamanta.in/how-git-works-the-importance-of-the-git-folder-explained?showSharer=true



