- What is Git?
- Linus Trovolda
- Why is it called Git?
- Github.com (Estb. 2007)
- Github Alternatives
- Github w/ JIRA/Trello (Agile SDLC)
- Git/Github Terms
- Git locally, brew install git
- git init
- git status
- git diff
- git add .
- git commit -m “this is a test commit (think of it as a tweet)”
- git push
- github create repo
- git remote
- git user
- git log
- git clone git pull
- git pull –rebase vs git pull (git fetch && git merge)
- git stash
- vim .gitignore
- Sample SDLC w. git
- Cloning and working on last nights home work
What is Git?
- Software for tracking changes in files
Helps coordinate distributed work for developers, released in 2005.
It’s open source and free and in it’s current form enables collaboration, revision management, debugging, CI/CD etc.
Before GIT became ubiquitous, SVN Apache Subversion or BitKeeper (paid) were used
Creator of Linux, wrote Git
Linux is a Kernel written in 1991 - vast majority of webservers are Unix/Linux based
Key features led to high user adoption - free, stable, secure, multi-user (distributed)
Apparently he unplugged, went away in a cabin and didn’t leave until it was written, made it available for free
Here’s a (70 minute) talk he gave at Google (2007), about Git
Why is it called Git?
Over 40 acronmyms for GIT - all true
Linus says he likes to name things after himself (like Linux) - but the more likely explanation is
git was sufficiently quirky and not a pre-existing Linux command
Github.com (Estb. 2007)
- leverage and added “social” elements to Git - a GUI, public + private + opensource code, a news feed, a graphical commit history
Github Pages (blog/personal websites), Github Gists (code snippet sharing)
word to the wise - they also have access to all your sourcecode, if you’re into privacy. MSFT paid ~$8 billion for a reason
- GitLab(open core), Bitbucket (By Atlassian), GitoLite (self hosted, access control layer on top of Git)
Github w/ JIRA/Trello (Agile SDLC)
- Repository (repo) - root folder of application (code)
- Remote Repo - hosted on a remote registry - aka
upstream repolike GH, GitLab etc
- Repo on your device (local repo aka locally)
- multiple people can work on that code (engineers, QA etc)
git config --global user.name "Mona Lisa"
- Cluster of users
- Let’s say Google Docs has one team of 8 developers and 16 QA engineers
- We have an org. nyu-csci-ua-0467-001-fall-2021 the org has one repo each for the weeks HW, and org has each of you added as a team + user. Why? So you can potentially add other users into the team for collaboration (not required)
forum like place to commment/report on bugs/RFC (esp useful in opensource/public libraries/packages)
e.g. npm version x not compatible with new macOS update
Git locally, brew install git
if you’re on a mac and have brew,
brew install git
else download it
check if it’s installed
- Git becomes aware but doesn’t care - it’s not tracking changes in the file
- you can add text into test.js but git wont track changes to it
git add .
Until you run
git add . or
git add <filename>, and then make changes git won’t start tracking changes. Adding a file is also called staging (preparing) it for a commit
- You’re allowed to change your mind
git commit -m “this is a test commit (think of it as a tweet)”
You’re happy with the progress you’ve made, you want to commit to it - write a message
Some write essays in the messages - i prefer 144 characters or less (be clear + concise)
git commit -m "should be like a tweet"
git commit --amend
- Pushing repo without an upstream (remote) repo will give an error
github create repo
- Login to github.com - create a new repo https://github.com/new
- You get a repo URL - https://github.com/osehgol/git-ws-test
push in peace
git push --set-upstream origin master
git config --global user.name "Mona Lisa"
- Is a history of your commits (squash, cherry pick, reset)
git clone git pull
- Sharing code is easy
git clone https://github.com/osehgol/git-ws-test.git
- once cloned - collaborator doesn’t need to
git remote add ...etc. s/he gets all the logs etc.
- Owner can now pull the change
git pull --rebase and they’ll have the updated test.js file
- For this class, you don’t need
git pullwould be fine
- Git lets you branch out your code into separate streams (so different developers can work on it) and then merge or rebase back into the main/master branch. At this time you’re not going to need branches but here’s how you create/switch between them.
git pull –rebase vs git pull (git fetch && git merge)
- when working with others on the main/master branch a good strategy is to pull with rebase everytime you want to get some fresh stuff from upstream
git pull --rebase
Rebasing is the process of moving or combining a sequence of commits to a new base commit (git rewrites logs internally to make them clean/linear).
this avoids conflicts and re-pushing of code which happens under merge (git logs get crazy in merge)
Example of rebase - stackoverflow
Which strategy to use atlassian
Golden rule of Git rebase -
never use it on public branches.
Sometimes - you’ll have local uncommited changes, but have to pull –rebase w. upstream.
git stash- it stashes your changes temporarily, clearing your branch for a conflict free
pull --rebase, you can then
git stash popyour changes back into branch OR
git stash clearif the changes are redundant
- tokens, keys, node_modules etc
Sample SDLC w. git
- git is versatile enough for orgs to figure out their own workflow. Here’s a sample.
Cloning and working on last nights home work
git clone https://github.com/nyu-csci-ua-0467-001-fall-2021/username-homework01
- already has .git dir in it - you’re ready to make, add (track), commit & push changes
echo 'test text' > src/connectmoji.js
git add .
git commit -m "git ws test"
- we can see your work
- not the rest of the class
- possible to add collaborators - but each of you are individually graded (check w. Prof Joe)