Sitemap

Useful Git commands — For Developers

3 min readApr 11, 2024

Useful git commands for developers

Git is a local version control system (VCS) that enables developers to save snapshots of their projects.

GitHub is a web-based platform that uses git’s version control features so they can be used collaboratively.

Here’s a rephrased version of the key terms:

  1. Repository: A compilation of source files dedicated to your project.
  2. Branch: Each repository features a primary (master/main) branch, housing production-ready or live code. Additional branches are created by developers for various purposes, such as experimentation or feature enhancements.
  3. Commit: In our project workflow, modifications involve adding new files, altering existing ones, or removing obsolete ones. Commits serve to mark these points of change.
  4. Push: Transmitting local changes to the remote repository (usually on GitHub).
  5. Pull: A request to integrate a commit into the default branch, typically for merging.
  6. Merge: The amalgamation of histories from two or more branches. Typically, a feature branch is merged into the default or deployment branch to incorporate new functionalities into the production environment.
  7. Tag: An indicator pointing to a specific commit, offering a lasting reference to a particular event. Tags are commonly employed in conjunction with semantic versioning to denote releases of your application.

Install Git

Link https://git-scm.com/download/win

Basic Git commands which every developer should know

The setup process for your local environment before using Git:

Before diving into Git commands, it’s crucial to configure some settings, such as user information. To establish your identity within a local Git repository, follow these steps:

Set your username by executing the command:

git config --global user.name "CodeWithTarun"

Set your email address with the command:

git config --global user.email "codewithtarung@gmail.com"

This ensures that your email is linked to your Git actions, facilitating communication and accountability within the repository.

initiating a Git project:

Ready to dive into our Git project? Let’s get started.

  1. Create a Folder: Begin by creating a new folder on your local system where you want to store your project files.
  2. Open Git Bash: Once the folder is created, right-click inside it and select “Git Bash here” from the context menu. (Note: This option becomes available after installing Git on your system.)
  3. Git Init: Now, let’s initialize this folder as a Git repository. The git init command sets up the directory to be managed by Git. It creates some hidden directories that Git needs to track changes effectively. Don't worry about these hidden directories; they facilitate Git's functionality behind the scenes. Once initialized, Git will start monitoring any changes made within this directory.
git init

After executing the git init command and kicking off your project, it's time to delve into the development process. As you work on your project and introduce new files, it's essential to keep track of these changes using Git.

To check the status of your project and identify any untracked files, utilize the git status command. This command provides a snapshot of the current state of your repository, highlighting any modifications or additions that have yet to be incorporated into Git's tracking system.

git status

Git add

Git add command is used to add the file in stage

git -- add <file name>

Git rm

Git rm command is used to remove the file in unstage

git -- rm cached <file name>

git commit

Git commit with switch -m allows us to commit the files in local repository.

git commit -m "comment message"

Git branch

To create a new branch in the repository, we use git branch <BranchName>

git branch apexfeatureSf

After creating a branch using the git branch command, it's essential to switch to that branch to start working on it effectively. To do this, you'll use the git checkout <branchname> command.

For instance, if you have a branch named “ApexfeatureSf” that you want to work on, simply execute the following command:

git checkout apexfeatureSf

When you’re working with multiple branches in Git, eventually, you’ll want to combine the changes from one branch into another. This is where the git merge command comes in handy.

Let’s say you’re currently in the “apexfeatureSf” branch and you want to integrate the changes from the “main” branch into it. In this scenario, you’d execute the following command:

git merge main

#SalesforceDeveloper

Please free to reach out to me if you need any help from my side.

https://www.linkedin.com/in/thetarungupta/

--

--

Tarun Gupta
Tarun Gupta

Written by Tarun Gupta

Founder @Vivaansh Consulting | Tableau Ambassador | Leader | Public Speaker | Certified Tableau & Slack Consultant | DataDev | Data Steward