hey everyone,As the heading says, it is a saviour in time as well as in data protection.we can commit and push it to our remote repo and pull it whenever we want to. Last week we discussed about the git in local repository. Today we'll talk about whats happening in remote repository. so for that i'll introduce some git commands.

git remote
This command is used to connect your local repo to your remote server.
git remote add origin <host-or-remoteURL>
git push
This command sends the committed changes of master branch to your remote repository.
git push origin <master>
Replace <master> with the branch where you want to push your changes.

Git cherry - pick

git cherry-pick is a powerful command that enables  arbitrary Git commits to be picked by reference and appended to the  current working HEAD. Cherry picking is the act of picking a commit from  a branch and applying it to another. git cherry-pick can  be useful for undoing changes.                                                                                                             For example, say a commit is accidently  made to the wrong branch. You can switch to the correct branch and  cherry-pick the commit to where it should belong.

main uses are :-

1) Team collaboration

2) Bug hotfixes

3) Undoing changes and restoring lost commits

Team collaboration.

Often times a team will find individual members working in or around the same code. Maybe a new feature has a backend and frontend. Maybe the backend developer creates a data structure that the frontend  will also need to utilize. The frontend developer could use git cherry-pick to pick the commit in which this data structure was  created. This pick would enable the frontend developer to continue  progress on their side of the project.

Bug hotfixes

When a bug is discovered it is important to deliver a fix to end  users as quickly as possible. For example ,a developer  has started work on a new feature. During that new feature development  they identify a pre-existing bug. The developer creates an explicit  commit patching this bug. This new patch commit can be cherry-picked  directly to the master branch to fix the bug before it effects more users.

Undoing changes and restoring lost commits

Sometimes a feature branch may go stale and not get merged into master. Sometimes a pull request might get closed without merging. Git never loses those commits and through command git log they can be found and cherry picked back to life.

To demonstrate how to use git cherry-pick let us assume i have a repository with the following branch state:
    a - b - c - d   Master         
         \e - f - g Feature
git cherry-pick usage is straight forward and can be executed like:
git cherry-pick 'commit hash'
In this example 'commit hash' is a commit reference. You can find a commit reference by using git log. In this example i have constructed lets say i wanted to use commit `f` in master. First i ensure that i am working on the master branch.
git checkout master
Then i execute the cherry-pick with the following command:
git cherry-pick f
Once executed my Git history will look like:
    a - b - c - d - f'   Master         
         \e - f - g     Feature
The f commit has been successfully picked into the feature branch.

This is all for this week, see you all on the next blog.