Nitin Agrawal
Contact -
  • Home
  • Interviews
    • InterviewFacts
    • Resume Thoughts
    • Daily Coding Problems
    • BigShyft
    • Companies >
      • InvestmentBanks >
        • ECS
        • Bank Of America
        • WesternUnion
        • WellsFargo
      • ProductBasedCompanies >
        • Google
        • Microsoft >
          • Microsoft
        • CA Technologies
        • Model N India
        • Verizon Media
        • Oracle & GoJek
        • IVY Computec
        • Nvidia
        • Samsung
        • ClearWaterAnalytics
        • ADP
        • ServiceNow
        • Pubmatic
        • Expedia
        • Amphora
        • CDK Global
        • Delphix
        • Fractal Enterprises LLP
        • CDK Global
        • Tide-Banking
        • Epic
        • Sincro-Pune
        • Whiz.AI
        • ChargePoint
      • ServiceBasedCompanies >
        • Sapient
        • Altimetrik
        • ASG World Wide Pvt Ltd
        • Paraxel International & Pramati Technologies Pvt Ltd
        • MitraTech
        • Intelizest Coding Round
    • Interviews Theory
  • Programming Languages
    • Java Script >
      • Tutorials
      • Code Snippets
    • Reactive Programming >
      • Code Snippets
    • R
    • DataStructures >
      • LeetCode Problems
      • AnagramsSet
    • Core Java >
      • Codility
      • Threading >
        • ThreadsOrder
        • ProducerConsumer
        • Finalizer
        • RaceCondition
        • Executors
        • Future Or CompletableFuture
      • Important Points
      • Immutability
      • Dictionary
      • URL Validator
    • Julia
    • Python >
      • Decorators
      • String Formatting
      • Generators_Threads
      • JustLikeThat
    • Go >
      • Tutorial
      • CodeSnippet
      • Go Routine_Channel
      • Suggestions
    • Methodologies & Design Patterns >
      • Design Principles
      • Design Patterns >
        • Decorator
        • Proxy
        • Lazy Initialization
        • CombinatorPattern
        • RequestChaining
        • Singleton >
          • Singletons
  • Frameworks
    • Apache Velocity
    • Spring >
      • Spring Boot >
        • CustomProperties
        • ExceptionHandling
        • Issues
      • Quick View
    • Rest WebServices >
      • Interviews
      • Swagger
    • Cloudera BigData >
      • Ques_Ans
      • Hive
      • Apache Spark >
        • ApacheSpark Installation
        • SparkCode
        • Sample1
        • DataFrames
        • RDDs
        • SparkStreaming
        • SparkFiles
    • Integration >
      • Apache Camel
    • Testing Frameworks >
      • JUnit >
        • JUnit Runners
      • EasyMock
      • Mockito >
        • Page 2
      • TestNG
    • Blockchain >
      • Ethereum Smart Contract
      • Blockchain Java Example
    • Microservices >
      • Messaging Formats
      • Design Patterns
    • AWS >
      • Honeycode
  • Databases
    • MySql
    • Oracle >
      • Interview1
      • SQL Queries
    • Elastic Search >
      • StudySources
  • Random issues
    • TOAD issue
    • Architect's suggestions
  • Your Views
Few useful Git commands -
---To list the repositories linked -
git remote -v


Most people used 'upstream' instead of 'master', it is just a personal choice for your own understanding.
But I use 'master', as everything on Git is 'upstream' for me, either it is 'origin' or anything else, so I used 'master' for 'Compliance-R'

---To add a repository like shown, 'origin' will be default which you can change in your git settings -
git remote add master <master git url>
Using above command you can add multiple remote repositories by just changing the name like 'master' used above.
---To get the latest references from the remote repository -
By default, you will be on 'origin', so using -
git fetch
will be sufficient, as it means to fetch latest references from 'origin'
To fetch from other remote repository -
git fetch master
---To get the list of branches from all repositories local & remote both -
git branch -a

Current local branch will be marked with * & Green color.
---To checkout the remote branch with different name in your local -
git checkout -b <localBranchName> origin/<branchName>
---To check the commit history
git log --pretty=format:"%h - %an, %ar : %s"
 
If you don't want all details shown above then use -


If you want more details then use -


---To squash various commits into 1 commit, may be to clean your commit history -

Suppose I want to squash all the commits done after 62bd577a, the commit at the bottom in above image
I want to squash all 9 commits into 1, then use below command -

git rebase -i HEAD~9
In next window you will be presented all the 9 commits, there select which commit you want to pick & use squash to squash that commits.
Check using 
git log, & all your squashed commits will be as one commit.
---To push your changes after making any change in commit history or rebasing etc -
After such changes, you will get error during normal push, due to possible conflicts.
So you need to do force push using : 
git push --force
---To do the rebase of your branch with master or any other repository branch -
This is one tricky & thankless work while working with Git.
Use below command -

git rebase master/<branchName>
If you are lucky then no conflicts will come & rebase will be done.
If conflicts come then you need to resolve by confirming what changes you want to pick or ignore, resolve all the kind of errors.
Then add that file : 
git add <fileName>
After resolving for every file & adding that like above, say : git rebase --continue
Note : Keep in mind about cherry-pick in Git, it can be helpful if you just need to selective commits from the source.
git cherry-pick <commit_id from source>
---To delete the local branch even it has pending commits -
git branch -D <localBranchName>
Powered by Create your own unique website with customizable templates.