#3 Workshop on Git
What is Git
In case of fire: git commit, git push, leave the building
HandsOn #1: Simple Commands
#1. Go to Github.com/Gitlab.com and create a remote Git repository.
#2. Copy the git address that you can clone
#3. On your terminal, clone your remote repository
git clone <copied git address>
#4. Initialize a npm package
npm init
#5 Add your package.json to staging
git add package.json
#6 Look at status of your git repository
git status
#7 Commit your changes
git commit -m "Added package.json"
#8 Push your changes (In Gitlab you might have to give permissions to push)
git push origin master
#9 Create a file named <index.html>... Stage, Commit & Push it
git: history is written by commiters
# Git knows what you did last summer!
git log
Don't let the walls cave in on you, git knows where your HEAD's at
Branching
#1. create a new branch named "setup_jest" and switch to it using
git checkout -b setup_jest #-b to create a new branch
#2. Install jest and look at the status
npm install jest --save
git status
#3. Gitignore file.. You don't need node_modules
"node_modules/" >> .gitignore
# git status... Now node_modules are gone.. Yo!
#4. Commit and push your branch to master
#5. Checkout master & Look at your package.json.
Git gets easier once you get the basic idea that branches are homeomorphic endo-functors mapping sub-manifolds of a Hilbert space.
#Let's emulate a merge conflict
1. Go to your Github.com/Gitlab.com repository
2. update the README.md file with author name
3. Save and commit in master
4. In your local repository, go and update README.md file with description
5. Stage, commit and push!!
### Merge conflicts resolution...
Merges & Rebase
Rebasing
# Lets try rebasing
1. git checkout master #move to master
2. git checkout -b branch1 # create a branch named readme_changes1 and checkout to it
3. make some changes to Readme file.
4. git add Readme.md
5. git commit -m "changed Readme.md"
6. git push origin branch1.
7. git checkout master
8. git checkout -b branch2
9. touch branch2_file.txt
10. git commit -am "added txt file in branch2" # -am equals git add .; git commit -m "";
11. git push origin branch2
11. git rebase branch1 # now branch2 base off from branch 1 and code changes are reflected
// see the code changes
merge another branch into the branch where you are currently working, and move all of the local commits that are ahead of the rebased branch to the top of the history on that branch
Commits are not objects of love, and should not be judged by their size
Atomic Commits
If you have anything staged, commit now or stash forever
git stash drop: Hey! That stuff's expensive.
This is not the greatest commit in the world, this is just a cherry-pick.
[TechInX] Workshop on Git
By Yeswanth S
[TechInX] Workshop on Git
- 635