Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    • Top 10 PMD Issues Salesforce Developers Should Focus on in Apex
    • How to Use Graph API for Outlook-Salesforce Connection
    • Enhancing Performance with File Compression in Apex
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Friday, May 16
    • Home
    • Architecture
    • Salesforce
      • News
      • Apex
      • Integration
      • Books Testimonial
    • Questions
    • Certification
      • How to Prepare for Salesforce Integration Architect Exam
      • Certification Coupons
    • Integration Posts
    • Downloads
    • About Us
      • Privacy Policy
    SalesforceCodex
    Home»Salesforce»Useful Git Commands

    Useful Git Commands

    Dhanik Lal SahniBy Dhanik Lal SahniMarch 24, 2020Updated:May 12, 20201 Comment4 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Useful Git Commands
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Version Control is important for Team-Based Development for every organization.  We can use TFS or Git for versioning control.

    What is Git?

    Git is distrbuted version control system. Distributed version control systems give developers flexibility and freedom by providing every collaborator with a copy of the entire repository at any time, including all branches (lines of work) and commits (saved points in history) on a developer’s local machine.

    What is Github?

    Github is collaboration platform built on top of Git. GitHub serves as a community space where we can share our work, see our team’s work, complete code reviews, and connect integrations that help us build, test, and deploy our code. GitHub is home to the largest collection of open source projects in the world.

    We can utilize git commands for GitHub and TFS code as well.

    Git Commands :

    Local Environment Setup before using Git:

    We should set some configuration before using git commands like user information.

    To set user name for local git repository use below commands

    git config --global user.name "Dhanik Sahni"

    To set user email for local git repository use below commands

    git config --global user.email "dhanik.sahni@yahoo.com"

    Git Network Command:

    Git has four network commands git clone, git fetch, git pull, and git push which work for local and remote repository.

    git clone

    Git clone is a git command line tool which is used to target an existing repository and create a clone, or copy of the target repository
    1. Cloning to a specific folder

    git clone <repo> <directory>
    git clone https://github.com/dhaniksahni/rotateGlobeInLightning.git c:\code

    2. Cloning a specific branch

    git clone branch <branch> <repo>
    git clone -branch new_feature https://github.com/dhaniksahni/rotateGlobeInLightning.git
    here new_feature is branch
    

    git fetch

    The git fetch command downloads commits, files, and refs from a remote repository into local repository. It will download the remote content but not update local repo’s working state, leaving current work intact.

    git fetch <remote>
    https://github.com/dhaniksahni/rotateGlobeInLightning.git
    git fetch <remote> <branch>
    https://github.com/dhaniksahni/rotateGlobeInLightning.git new_feature

    git pull

    The git pull command is used to fetch and download content from a remote repository and immediately update the local repository to match that content.

    git pull <remote>  -- Fetch the specified remote’s copy of the current branch and immediately merge it into the local copy. 
    git pull https://github.com/dhaniksahni/rotateGlobeInLightning.git

    git push

    The git push command is used to upload local repository content to a remote repository. Pushing is transferring commits from local repository to a remote repository.

    git push <remote> <branch>
    git push https://github.com/dhaniksahni/rotateGlobeInLightning.git new_feature
    //new_feature is branch

    Other Important git commands

    git branch

    This will list out all local branches.

    git branch --List of local branches
    
    git branch myfeaturebranch --this will create new branch in local repository

    git checkout

    The git checkout command is used to switch between branches in a repository. Example : We have multiple branches for our repository and we want to take code for any specific branch. we can checkout for that specific branch.

    git checkout master  --master is branch
    git fetch

    git add

    This command will add file to local repository.

    git add README.md --Will add README.md in repository

    git commit

    The “commit” command is used to save our changes to the local repository. It will not push code automatically to the remote server. Using the “git commit” command only saves a new commit object in the local Git repository.

    git commit -m “Commit to resolve merge conflict” --This will commit and comment will be added

    git log

    The git log command enables us to display a list of all of the commits on current branch. By default, the git log command presents a lot of information all at once.

    git log -10 --will only show the 10 most recent commits.

    git diff

    git diff will compare between any two commits, branches, or tags in the repository.

    git diff 4e3dc9b 0cd75d4 --4e3dc9b and 0cd75d4 are commit #

    git revert

    git revert will undo changes. It can be used on commits at any point in the repository’s history without affecting other work. This will revert from remote repository as well.

    git revert <commit-id>  -- Commit-id will be checked using git log

    git reset

    This will help to rewind committed code to local repository. It will not revert code if it is already pushed to remote. Use git revert in that case.

    git reset --hard f414f31  --f414f31 is commit id
    

    Reference:

    https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-clone
    https://www.atlassian.com/git/tutorials/setting-up-a-repository

    git salesforce version control
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleService Component In Lightning Web Component
    Next Article COVID India Real Data In Lightning Community
    Dhanik Lal Sahni
    • Website
    • Facebook
    • X (Twitter)

    With over 18 years of experience in web-based application development, I specialize in Salesforce technology and its ecosystem. My journey has equipped me with expertise in a diverse range of technologies including .NET, .NET Core, MS Dynamics CRM, Azure, Oracle, and SQL Server. I am dedicated to staying at the forefront of technological advancements and continuously researching new developments in the Salesforce realm. My focus remains on leveraging technology to create innovative solutions that drive business success.

    Related Posts

    By Dhanik Lal Sahni6 Mins Read

    Top 10 Salesforce Flow Features of Salesforce Summer ’25

    May 11, 2025
    By Dhanik Lal Sahni6 Mins Read

    Unlock the Power of Vibe Coding in Salesforce

    April 30, 2025
    By Dhanik Lal Sahni5 Mins Read

    How to Implement Dynamic Queueable Chaining in Salesforce Apex

    April 21, 2025
    View 1 Comment

    1 Comment

    1. Dhanik Lal Sahni on March 30, 2020 12:31 am

      Thank You Abhishek.

      Reply
    Leave A Reply Cancel Reply

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (110) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) einstein (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (29) Lightning web component (61) lwc (50) named credential (8) news (4) optimize apex (3) optimize apex code (4) Permission set (4) Queueable (9) rest api (23) S3 Server (4) salesforce (140) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (110) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) einstein (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (29) Lightning web component (61) lwc (50) named credential (8) news (4) optimize apex (3) optimize apex code (4) Permission set (4) Queueable (9) rest api (23) S3 Server (4) salesforce (140) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Facebook X (Twitter) Instagram Pinterest YouTube Tumblr LinkedIn Reddit Telegram
    © 2025 SalesforceCodex.com. Designed by Vagmine Cloud Solution.

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.