DevOps Classroomnotes 01/May/2022

Git Collaboration Contd…

  • Git Repository exists already and you are supposed to get that into your local system and make changes.
  • Cloning a repository:
    • In this case you will get the contents of the remote repository (.git) into your local system and then git will generate the working tree
  • Lets Clone the new Repository. Refer Here.
    • The command is git clone <remote-repo-url>
      Preview
  • When we clone the repository the default remote name is origin
    Preview
    Preview
  • Lets understand collaboration by two users

    • khajaibrahimshaik (Windows Terminal)
      Preview
    • qtdevops (Git Bash)
      Preview

Scenario 1: Both users working on different folders in the same branch (main)

  • qtdevops user changes
    Preview
  • khajaibrahimshaik changes
    Preview
  • Let qtdevops push the changes
    Preview
  • Let khajaibrahim push the changes
    Preview
  • This error is happening as git expects origin/main to point to same commit id to what your remote-repo’s latest is
  • Now to resolve this i need to get the latest changes from remote
  • To get the latest changes from remote we use pull
    Preview
    Preview
    Preview
  • We got one extra commit due to pull as the merge b/w main and origin/main happened.
  • Lets continue the changes
    • qtdevops user does one more changes and tries to push
      Preview
    • Now qtdevops user needs to pull the latest changes but he doesn’t like the idea of extra commit
      Preview

Exercise: Create a new repository called as GitLearning in Github

  • Clone the repository into your system
  • Create a new branch from main called rel_v1.0
  • In that branch create two commits and push the changes.
    Preview
    Preview
    Preview

Scenario 2: Both users working on same files leading to conflicts while push

  • Let qtdevops user add some changes in docs/Readme.md
  • Let khajaibrahimshain add some changes and push the changes
    Preview
  • Now if qtdevops user tries to push without pull he will get error, so he tries to use git pull --rebase
    Preview
    Preview
    Preview

Difference between git push and git push

  • The error scenario:
    Preview
  • In Git upstream refers to the remote repository and set upstream command will set default remote for your branch.
  • When you clone the repository and work on existing branches there is no need to set the upstream, but when you create a new branch in the repository and if you are pushing the branch for the first time, the upstream can be set git push -u <remote-name> <branch-name>
  • If the branch is already created by you and if you had the push the changes without setting upstream then you can set upstream by the following command git push --set-upstream <remote-name> <branch-name>
    Preview
  • Note: Always pull the changes before pushing to the remote repository.

Git clone types

  • Bare clone of spring petclinic:
    • command: git clone --bare <url>
      Preview
  • Mirror clone of game of life
    Preview

Next Topics

  • Git Tags
  • Git Pull requests
  • Forks & Pull requests
  • Git Hooks
  • Git Submodules
  • Git Configurations
  • Useful Git Commands

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner