The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
Github fundamentals to work with legendary projects
1. GITHUB fundamentals to work on legendary projects
1
GITHUB fundamentals to work on legendary projects
By Ravi Shankar
Fork the project which you want to work on. For example I have cloned passionbytes/arrowexp
(main project) to Ravion/arrowexp (forked project). Note that when you fork, you have everything
in sync at that point and will have only one branch – mainly master.
Figure 1 Fork a project
Now, we want to contribute to the main project. The official way is to clone it to the local as
below as the first step.
git clone https://github.com/Ravion/arrowexp.git
This is shown below:
2. GITHUB fundamentals to work on legendary projects
2
Figure 2 git clone the forked project to local
Note that now we have three things – one is main project, another is the forked master, and the
local copy.
Since you may make changes later, at any point in time, we need to make sure we are syncking
our local code is in sync with main master. This is done by
git remote add upstream
https://github.com/passionbytes/arrowexp.git
Figure 3 Remote repo setting
Assume that at this time, someone changed the main project by editing first number in csv from
90 to 100 and committed.
3. GITHUB fundamentals to work on legendary projects
3
Figure 4 master edited now (from 90 to 100 on first value)
Now we have a problem. Our local code , neither our forked master are in sync with main project.
So lets issue a sync command, by
git fetch upstream
Figure 5 Syncing with main project
4. GITHUB fundamentals to work on legendary projects
4
The most important thing is, now the forked master is not updated with sync, only our local copy
is updated:
Figure 6 Left side and right side shows the we just fetched, not updated anything
So lets try now, a powerful command: rebase
git rebase upstream/master and see what happens
Figure 7 The forked project on github is not updated, but local is
This is very important : now we have same code as that of main project and our local , but NOT
THE FORKED PROJECT IN GITHUB
Ignore that for now. Lets start making a change in the csv file, changing value from 100 to 110.
Since we are working on a certain feature or improvement, we will create a branch with the
feature name and we will start building it. This is the command next, assuming that we are
adding a wonderful feature now.
5. GITHUB fundamentals to work on legendary projects
5
git checkout -b first-wonderful-changes upstream/master
You will now be in that branch.
Figure 8 Creating a branch
Now let’s make changes by editing the CSV file from 100 to 110. Shown below new changes
Figure 9 Editing the code
Now type
git status
6. GITHUB fundamentals to work on legendary projects
6
Figure 10 Status of the branch
Many things here. We first changed to our branch, then we edited our file. When we look for
status, it will say that there is one file modified now. Now we have to add it for committing,
followed by a commit. After adding it, you cant do any rebase, before committing. We execute
below commands:
git add drivers.csv
git commit -m "first wonderful changes"
git rebase upstream/master (Just making sure nobody made any further
changes from the point we created branch)
You get below.
7. GITHUB fundamentals to work on legendary projects
7
Figure 11 Adding , Committing and Rebasing
Note that we have not told to update this code yet.
We are taking a coffee break. Meanwhile something is happening in the main project.
We just committed, but not pushed. Now let’s assume that some author is making a change in
the main master project, by editing the same CSV file , last line from 45 to 100 and committed.
Shown below
Figure 12 Main authors(s) editing csv file in main project
How do we make sure that when we push it, we have the latest ?
Just do the following command, and see the effect
8. GITHUB fundamentals to work on legendary projects
8
git fetch upstream à get the latest changes
git rebase upstream/master -> rebase our code, and replay the changes we
have done
cat drivers.csv à shows that the latest changes are updated, and git had applied
our changes on top
Figure 13Making sure that we are taking latest changes
Now finally, we are going to push it. This is done in two steps. First, we need to create one
remote repo to point to our forked project with our branch name. Then create a pull request from
that branch.
Let’s create one remote repo, pointing to our forked master. Remember we never did any update
yet there.
9. GITHUB fundamentals to work on legendary projects
9
git remote add ravion
https://github.com/Ravion/arrowexp.git
Figure 14 Add a remote repo to point to our forked master
Next step is to push our changes to this forked master, but to a feature branch. In this way, we
can create as many feature branches and the real forked master remain their as a placeholder as
root of tree.
This is done as:
git push --force-with-lease --set-upstream ravion
first-wonderful-changes
The output tells everything:
Figure 15 Pushing changes to our branch in forked master
10. GITHUB fundamentals to work on legendary projects
10
Now lets go to GIT, our forked master
Figure 16 Forked master shows a new branch with our changes
Figure 17 Changes in forked master, see branch name
If you look at the CSV file in master, there will not be any change from the first time we pulled.
But look at the branch’s CSV file
11. GITHUB fundamentals to work on legendary projects
11
Figure 18 Left side in master shows no change, but our branch shows the latest changes syncing
with main master
So far so good. Now we will create a pull request from our local branch.
Figure 19 Creating a PR from feature branch
Now let’s turn the roles. I am going to master, instead of approving the PR, I am giving a
comment to update the value to 150. At the same time, I am changing last row of CSV file to
200.
As a feature owner, now you need to change value, resubmit without creating a new PR, but on
same PR. Here is how file looks in main master
12. GITHUB fundamentals to work on legendary projects
12
Figure 20 CSV main master changes, asked to change value in first row to 150
OK, let’s come back where we are.
We start with
git checkout first-wonderful-changes à NOTE that no -b option. -b
option means we are creating new branch
Fetch and rebase to sync
git fetch upstream
git rebase upstream/master
and now see
car drivers.csv à you must see latest file
13. GITHUB fundamentals to work on legendary projects
13
Figure 21 Syncing for next iteration
Now let’s change the value as per the comments by reviewer in main master
Figure 22 Making changes as of review
14. GITHUB fundamentals to work on legendary projects
14
OK, now , replay what we did before: May be you can choose a different commit message.
Figure 23 Making changes as per review and committing branch again
You can note that, now the changes are available in our forked branch, as well as message gone
to main master for next review. Once reviewed, your branch as well as the main master is
synchronized.