Git Remote
- Fourth area of Git: Remote Repo

- To handle the centralization of work done by multiple people in your organization we will have a central Repository/Remote Repository

- The Remote Repository in Git are generally referred as Git Remote Server/Git Servers & these can be installed and maintained your organization or they can use cloud based Remote Repositories
- Remote Repositories have majorly two additional features
- daemon with some protocol to connect (https/ssh)
- user management
- Self Hosted Remote Repositories
- Gitolite
- Git lab Self Hosted
- Bit Bucket Self Hosted
- Cloud Hosted or Provider Hosted Remote Repositories
- GitHub
- Gitlab
- BitBucket
- Azure Source Repos
- AWS Code Commit
- Lets start understanding how the remote repositories can be working along with local repositories
- Lets look at graph of the changes you have done

- Now lets create a remote repository in GitHub which is public

- The repository is hosted on using two protocols
- https:
https://github.com/GitPracticeRepo/understanding.git - ssh:
git@github.com:GitPracticeRepo/understanding.git
- https:
- We have create a github repo for
understanding
- Now we need to send the commits from local repo to git hub
- So to do this, we need to inform our local repository about a remote repository
git remote add '<name-of-remote>' '<url-of-remote>'
- In git we generally use the name of remote as ‘origin’
git remote add origin 'https://github.com/GitPracticeRepo/understanding.git'

- Now lets push the changes to the remote repository
git push <name-of-remote> <branch-to-push>
- So our command would be
git push origin master

- When we connect with a remote repository, remote tracking branches will be created in your local system

- Lets make one more change in the local repo and commit the changes

- Now when we want to push the changes to remote repository for a particular branch, the condition origin/master and the master in the remote server should be looking at same commit id. If that is not the case the push fails

- Now lets push the changes

- Now for user2 lets try to create a clone

- Now let user2 make a change and create a local commit

- Now let user1 make the change and create a local commit

- Now let user1 push the changes to the remote repository

- Now if the user2 pushes changes to remote repository they will fail as the user2 tracking branch is not pointing to same commit id as remote repository i.e. we donot have latest changes in our local repository

- To get the latest changes from remote repository into your local repo
- Fetch the changes from remote repo to your tracking branch
- merge the changes from tracking branch to local branch
- Git pull command does both i.e (Git pull => git fetch + git merge)

- Now lets push

- Now lets make one commit for user 1

- Now if we push from user1 it would fail

- If we use git pull then it will create an extra commit which user1 doesn’t like so he uses the following command
git pull --rebase

