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>
- The command is
-
When we clone the repository the default remote name is
origin
-
Lets understand collaboration by two users
- khajaibrahimshaik (Windows Terminal)
- qtdevops (Git Bash)
- khajaibrahimshaik (Windows Terminal)
Scenario 1: Both users working on different folders in the same branch (main)
- qtdevops user changes
- khajaibrahimshaik changes
- Let qtdevops push the changes
- Let khajaibrahim push the changes
- 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
- 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
- Now qtdevops user needs to pull the latest changes but he doesn’t like the idea of extra commit
- qtdevops user does one more changes and tries to push
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.
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
- Now if qtdevops user tries to push without pull he will get error, so he tries to use
git pull --rebase
Difference between git push and git push
- The error scenario:
- 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>
- Note: Always pull the changes before pushing to the remote repository.
Git clone types
- Bare clone of spring petclinic:
- command:
git clone --bare <url>
- command:
- Mirror clone of game of life
Next Topics
- Git Tags
- Git Pull requests
- Forks & Pull requests
- Git Hooks
- Git Submodules
- Git Configurations
- Useful Git Commands