How to Simple Git Cherry-pick Copy Commit from another/upstream Github Repository

 

How to Simple Git Cherry-pick Copy Commit from another/upstream Github Repository

Prerequisite :

Download and Install Visual Studio Code
Download and Install Github Desktop
Download and Install Git CMD

– Origin Branch must have related / identical code with Upstream Branch (Base Branch)

– For example :
(source repo) Upstream repo –> github.com/otherusername/source<– you had forked / clone this repo to your own github account.
now your repo will be –> github.com/yourusername/myrepo
(you can rename to any name you want)

you edit this repo github.com/yourusername/myrepo and customize like edit emoji and many personalization. but you still need minor updates / major updates / important updates from Upstream repo (source repo) for sure. it’s time you need to use git cherry-pick methods to pick important commits / updates you may think its needed.

LET’S BEGIN
(please note, this steps are for first time, after done this, you must know which steps that no need to repeat)

First, open Visual Studio Code
– Navigate to Terminal > New Terminal
1)
Clone your forked / imported repo / your edited repository
git clone https://github.com/vishnoe115/myrepo
cd myrepo
 (to change directory of repo folder)

2)
– On Visual Studio Code click at Git Logo (Source Control) menu, then Open Folder, navigate to same folder/directory repository been cloned by Terminal of Visual Studio Code above
– Open terminal again if it’s closed.

3)
– Login to Github Desktop
– on Github Desktop choose Add an Existing Repository from your local hard drive
– navigate to same folder/directory repository been cloned by Terminal of Visual Studio Code above

** follow the rest on my Youtube Video in Channel Wiszky Howto
4)
Check all existing branches
git branch
  heroku
  h-code
* master

4.1 – To switch which branch that you want to apply updated git
git checkout [branch name]

5)
Add upstream remote (upstream repo) and name it “upstream_remote”
git remote add upstream_remote https://github.com/wisaenergy/source

6)
Check all remotes by this command below
git remote -v

you will see like this below
origin    https://github.com/vishnoe115/myrepo (fetch)
origin    https://github.com/vishnoe115/myrepo (push)
upstream_remote https://github.com/wisaenergy/source (fetch)
upstream_remote https://github.com/wisaenergy/source (push)

7)
Now Fetch the latest version of master (fetch all branches) from remote “upstream_remote”
git fetch upstream_remote

8)
Goto the branch where you want to apply the commits.
if you already in branch you want to apply, then skip this step.
git checkout h-code
* This “h-code” branch is in “origin” remote

9)
cherry-pick the commit from newly added  upstream_remote and apply.
git cherry-pick [commit-id]

10)
on Github Desktop Click on Push origin — and you’are done. Now you can see that you have been updated your edited repository with latest fix / mirror fix / or whatever commit you need from official repository to put in your edited /forked repository.

11) In Github Desktop you can git cherry pick by dragging commit from commit history to any branch you want.

Note : If you facing cherry-pick conflict on Github Desktop, you have to edit it manually using notepad++ / or if conflict when execute cherry-pick on Visual Studio Code you can edit code directly in Visual Studio Code (VS Code). Parts that made it conflicted, will marked like this <<<<<<< HEAD
you need to delete or replace it correctly, also you should have a bit knowledge. This happen because sometime if we edit or add part in the code it will change the code line, or different line made it conflicting.
after it’s done and marked that’s no conflict, you can apply commit by click Push origin on Github Desktop / Visual Studio Code.


EXTRAS :
* You can use $git log command to find the commit-id from upstream_remote branches.
* Example:
 $git log -n 5 upstream_remote/branch_name

Post a Comment

أحدث أقدم