Overview
- 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
- Repository
- User/Collaborator
- Organization
- Teams
- Issues
- Git locally, brew install git
- git init
- git status
- git diff
- git add .
- unstage
- 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
- Branch
- 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
- Tools
What is Git?
- Software for tracking changes in files
![](/images/git-diff.png)
-
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
Linus Trovolda
-
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
![](/images/GIT-acronym.png)
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
![](/images/github-contributions.png)
-
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
Github Alternatives
- GitLab(open core), Bitbucket (By Atlassian), GitoLite (self hosted, access control layer on top of Git)
Github w/ JIRA/Trello (Agile SDLC)
![](/images/github_trello.png)
Git/Github Terms
Repository
- Repository (repo) - root folder of application (code)
- Remote Repo - hosted on a remote registry - aka
upstream repo
like GH, GitLab etc - Repo on your device (local repo aka locally)
User/Collaborator
- multiple people can work on that code (engineers, QA etc)
git config --global user.name "Mona Lisa"
Organization
Teams
- 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)
Issues
-
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 --version
git version 2.21.0 (Apple Git-122.2)
git init
mkdir git-ws-test && cd git-ws-test
git init
ls -lah
![](/images/git_init.png)
git status
touch test.js
ls
git status
![](/images/git_status.png)
- Git becomes aware but doesn’t care - it’s not tracking changes in the file
git diff
- you can add text into test.js but git wont track changes to it
git diff
echo 'hello world' > test.js
cat test.js
hello world
git diff
#returns nothing
git diff test.js
#returns nothing
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
![](/images/git_add.png)
git add .
echo "you're added. am i being tracked?" >> test.js
cat test.js
git diff
![](/images/git_added.png)
unstage
- You’re allowed to change your mind
use "git rm --cached <file>..." to unstage
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 add . #the updated message
git commit -m "should be like a tweet"
git commit --amend
![](/images/git_commit_amend.png)
git push
- Pushing repo without an upstream (remote) repo will give an error
git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using
git remote add <name> <url>
and then push using the remote name
git push <name>
github create repo
- Login to github.com - create a new repo https://github.com/new
![](/images/git_create_repo.png)
- You get a repo URL - https://github.com/osehgol/git-ws-test
![](/images/git_repo_setup.png)
git remote
git remote add origin https://github.com/osehgol/git-ws-test.git
git remote -v
-
push in peace
git push --set-upstream origin master
git user
git config --global user.name "Mona Lisa"
git log
git log
- Is a history of your commits (squash, cherry pick, reset)
![](/images/git_log.png)
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 init
,git remote add ...
etc. s/he gets all the logs etc.
echo 'this is a collaborators input' >> test.js
git add .
git commit -m "collaborators input"
git push
- 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
--rebase
justgit pull
would be fine
Branch
- 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 branch
git checkout -b test_branch
git branch
git checkout master
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.
git stash
-
Sometimes - you’ll have local uncommited changes, but have to pull –rebase w. upstream.
-
Use
git stash
- it stashes your changes temporarily, clearing your branch for a conflict freepull --rebase
, you can thengit stash pop
your changes back into branch ORgit stash clear
if the changes are redundant
vim .gitignore
- 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.
![](/images/git_workflow.png)
Cloning and working on last nights home work
git clone https://github.com/nyu-csci-ua-0467-001-fall-2021/username-homework01
cd username-homework01
ls -lah
- already has .git dir in it - you’re ready to make, add (track), commit & push changes
![](/images/git_hw01.png)
echo 'test text' > src/connectmoji.js
git add .
git commit -m "git ws test"
git push
- 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)
Tools
-
Handy tools
- Bash-it
- SourceTree