Git+&+Github+Course +Git+Workflows
Git+&+Github+Course +Git+Workflows
workflows
(for collaboration)
Centralized
Workflow
AKA Everyone Works On Master/Main
AKA The Most Basic Workflow Possible
master
David clones the repo
master
Forrest clones the repo
master
Forrest gets to work on a
new feature! Adding and
Committing all day long!
master
Forrest now pushes up his
new work to Github
master
Pamela has also been
hard at work on her own
new feature.
master
She tries to push her new
work up to Github, but she
runs into trouble!
master
Failed to push. Updates were rejected
because the tip of your current branch is
behind its remote counterpart. Merge the
remote changes (e.g. 'git pull') before
pushing again.
So she pulls to get the
changes from origin master
Forrest's work must be
merged in. Hopefully this master
goes relatively smoothly!
Now that she has merged the
latest work from Github, she
can push her master branch up!
master
David working on a new feature, but is
having some doubts.
master
Now he can finally push his work up to
Github. His teammates can pull to get
his new commits.
master
The Problem
While it's nice and easy to only work on the master branch,
this leads to some serious issues on teams!
master
Pamela clones the repo
master
David clones the repo
master
David starts work on a new
feature. He does all this work
on a separate branch!
add-dark-theme
master
David wants Pamela to take a look
at his new feature. Instead of
merging it into master, he just pushes
his feature branch up to Github!
add-dark-theme
master
Pamela is hard at work on her own
new feature. Just like everyone else,
she's working on a separate feature
branch rather than master.
master
animated-scroll
Pamela hears from David that he
wants her to take a look at his new
work. She pulls down his feature
branch from Github.
add-dark-theme
master
animated-scroll
Pamela takes a look at the code and
makes a couple improvements of her
own. She adds/commits on the same
feature branch.
add-dark-theme
master
animated-scroll
Pamela pushes up her new work on
the add-dark-theme feature branch
so that David can pull them down.
add-dark-theme
master
animated-scroll
David returns to work the next
morning. After an hour on reddit he
decides he should actually do some
work.
add-dark-theme
master
David fetches from Github and sees
that there is new work on the add-
dark-theme branch. He pulls the
changes down and continues work.
add-dark-theme
master
David decides he is happy with the
new feature, so he merges it into
master!
*At a real company, you don't just
decide you are "happy with" a feature.
There are mechanisms for code
approval and merging we'll discuss
shortly!
master
David pushes up the updated master
branch to Github. The others can
now pull down the changes.
master
Feature
Branch Naming
There are many different approaches for naming feature
branches. Often you'll see branch names that include
slashes like bug/fix-scroll or feature/login-form or
feat/button/enable-pointer-events
my-new-feature
master
My Github
my-new-feature
master
My Github
my-new-feature
master
Just like any other merge, sometimes there are conflicts that need
to be resolved when merging a pull request. This is fine. Don't panic.
You can perform the merge and fix the conflicts on the command
line like normal, or you can use Github's interactive editor.
My Boss's Local Machine
My boss can merge the branch and resolve the conflicts locally...
My newly-created fork...
Now What?
Now that I've forked, I have my very own copy of the
repo where I can do whatever I want!
master
animated-scroll
The Official Project Repo
My Local Machine
I make a clone of my forked repository
so that I can start working on it locally
Github
The Official Project Repo
My Fork
origin
My Local Machine
When we clone a repo, Git automatically
adds a remote called origin that points to
our forked repo on Github.
Github
The Official Project Repo
upstream
My Fork
origin
My Local Machine
Next, I add a remote pointing to the original
project repo (NOT the fork). This remote can be
named anything, but you'll often see "upstream"
or "original" used.
Github
The Official Project Repo
upstream
My Fork
origin
My Local Machine
I do some new work locally. Normally, I
would work on a feature branch, but only to
keep the diagrams simpler I'm not going to!
Github
The Official Project Repo
My Fork
origin
My Local Machine
To share my changes with others, I cannot
push to upstream. I don't have permission!
But I can push to origin (my Github fork)
Github
Next, I can make a pull request from my fork
on Github to the original project repository
The Official Project Repo
Pull Request
My Fork
My Local Machine
Github
Now I wait to hear from the project maintainers! Do
they want me to make further changes? It turns out
they accept and merge my pull request! Woohoo! The Official Project Repo
Pull Request
Accepted!!!
My Fork
My Local Machine
Github
The next day, I get back to work. The official
project repo now contains work done by other
collaborators. I don't have their new work on my The Official Project Repo
machine! I'm behind!
upstream
My Fork
origin
My Local Machine
Github
The Official Project Repo
upstream
My Fork
origin
My Local Machine
All I need to do is pull from upstream
(the original repo) to get the latest
changes in my local repo.
Github
The Official Project Repo
My Fork
My Local Machine
Now I have the latest changes from
the upstream repo! I can work on
some new features locally without
working about being out of date.
Github
Pull
Request The Official Project Repo
Pull
My Fork
Push
My Local Machine
To Summarize!
1. I fork the original project repo on Github
2. I clone my fork to my local machine
3. I add a remote pointing to the original project repo.
This remote is often named upstream.
4. I make changes and add/commit on a feature
branch on my local machine
5. I push up my new feature branch to my forked repo
(usually called origin)
6. I open a pull request to the original project repo
containing the new work on my forked repo
7. Hopefully the pull request is accepted and my
changes are merged in!
An Even
Briefer Summary
1. FORK THE PROJECT
2. CLONE THE FORK
3. ADD UPSTREAM REMOTE
4. DO SOME WORK
5. PUSH TO ORIGIN
6. OPEN PR