GIT - Ins/outs/etc
What is git?
- Distributed source control
- A "clone" is a full copy of the remote repository
- Branches and tags are lightweight
0
Advanced issue found▲
What is git?
Assumptions...
0
Advanced issue found▲
- You have a git client installed
- You know how to add files to the git index
- You know how to commit
0
Advanced issue found▲
The GIT model vs centralized source control
GIT/Hg
SVN/TFS/CVS
(distributed)
(centralized)
Source control server-side
Local working copies are complete repositories
Tom
Dick
Harry
Local working copies are one or more complete branches
Tom
Dick
Harry
Visual overview (clone)
"Remote" is a remote version of the repository, eg. hosted on gitlab.gs.mil
Full local working copy
> git clone git@gitlab.gs.mil:GPM/dissemination/fgdrt.git
Syncing changes from remote
- Sitution: A newer version of the "develop" branch has been pushed to the remote
- Objective: I want to integrate these changes into an existing local story branch, story branch is named "iss53" and push to a branch on the remote
*Upon regular merge, branch differences are added
as a single merge commit into the destination branch. Rebase
is a cleaner, but more complex, alternative to work in a team environment.
~/myproject [develop] > git pull # does an automatic merge into local develop from remote
~/myproject [develop] > git checkout iss53
~/myproject [iss53] > git merge develop # local gpm-123 branch now has new code from develop
~/myproject [iss53] > git push -u origin iss53 # pushed to remote origin, ready for merge request
Visual overview (merge)
Before
After merge
~/myproject [master] > git merge iss53
Forks
- Nothing too special, just another remote of a repository with a common commit ancestor
- Still need to manage merges between remotes
- Traditionally referred to as "upstream" for the parent repository and "origin" for the fork
- Forks can be managed through UI of git hosting (eg. gitlab/github), but can also be managed independently (eg. a fork can live across different git providers!)
Upstream
"Origin" or our "fork"
Local
*Typical flow
Example: "forking" the nestjs-template
- Assumes you have already forked the repository (either manually or through gitlab.gs.mil's UI) and have cloned your fork locally as the "origin" remote
- Objective: Your local repository will have an upstream pointed at the original nestjs-template repository and an origin pointed at your fork. Additionally, we will sync the master branch between the upstream and your fork.
~/myproject [master] > git remote add upstream git@gitlab.gs.mil:GPM/templates/nestjs-template.git
~/myproject [master] > git fetch --all # This + last command is all we need to add the upstream reference and pull branch refs
#------------ SYNC UPSTREAM "MASTER" BRANCH TO YOUR FORK'S "MASTER" BRANCH ------------
~/myproject [master] > git checkout -b umaster -t upstream/master # checkout a local umaster branch, tracking to upstream/master, yes this step can be replaced by direct merge into origin/master if you're looking to do that
~/myproject [umaster] > git checkout master
~/myproject [master] > git merge umaster # "master" branch in fork now in sync
Example
Creating and syncing a fork across two disparate git providers
Upstream => https://github.com/meilinger/example-repo
- Along the way, we'll create and push a new branch
- Also, we'll cover some additional cli git commands
Resources/Exercises
Cheatsheets
GIT: Intro
By Joe Meilinger
GIT: Intro
- 197