Download presentation
Presentation is loading. Please wait.
Published by한일 서 Modified over 6 years ago
1
Akshay Narayan (anarayan@comp.nus.edu.sg)
git up to speed with RCS Akshay Narayan
2
What git? Why git? A distributed version control
Allows for non-linear development Why git? A discussion to avoid! Read more here
3
git concepts Data stored – snapshot of filesystem
All data locally available Hence easy to be distributed Data integrity – checksum based git promise – if you commit, I store it safe for you Everything commit is checksummed before stored and hence git knows of every change you make The hash is calculated based on the contetns of a file or directory structure.
4
git concepts – 3 states & workflow
Modified – files changed Staged – marked modifications for commit Committed – stored in local repository (safe) clone Working directory Staging area Repository (.git directory) .git directory is where all metadata is stored; what get copied when you do a clone Working directory is one version (most likely the latest) of the filesystem uncompressed and placed on the disk to use/modify Checkout to modify Stage edits Commit
5
Setting up git Create your keys and let the server know of it
Setup your identity git uses this in the commits $ git config --global user.name “Akshay Narayan” $ git config --global user. Set up the push default git can push all branches or the one you are on now $ git config --global push.default simple
6
git basics Initializing a repo Clone an existing repo $ git init
$ git clone
7
git basics Check the status Viewing differences Stage modified files
$ git init $ git clone <path/url> git basics Check the status $ git status Viewing differences $ git diff README.md Stage modified files $ git add README.md
8
git basics Commit changes Rename file Delete a file
$ git init $ git clone <path/url> $ git status $ git diff <file> $ git add <file(s)> git basics Commit changes $ git commit $ git commit –m “message” Rename file $ git mv <old> <new> Delete a file $ git rm <file> View commit history $ git log No SourceTree equivalent; Depend on file manager
9
git intermediate Remotes Show remote Add remote Fetch from remote
$ git init $ git clone <path/url> $ git status $ git diff <file> $ git add <file(s)> $ git commit $ git mv <old> <new> $ git rm <file> $ git log git intermediate Remotes Show remote $ git remote -v Add remote $ git remote add <name> <url> E.g. $ git remote add upstream Fetch from remote $ git fetch <remote name> E.g. $ git fetch upstream Push to remote $ git push <remote> <branch> E.g. $ git push upstream master Remove remote $ git remote rm <name>
10
Branching Diverge from the main development line git Branch
Commit tree Commit parents Branch is a pointer! Branches are lightweight Encouraged: Branch often, merge often! Images from:
11
git most useful! (aka advanced)
$ git init $ git clone <path/url> $ git status $ git diff <file> $ git add <file(s)> $ git commit $ git mv <old> <new> $ git rm <file> $ git log $ git remote -v|add|rm $ git fetch <remote> $ git push <rmt> <brnch> git most useful! (aka advanced) Creating branches $ git branch <branch name> $ git checkout -b <branch name> Switching to branch $ git checkout <branch name> HEAD pointer Denotes current branch Switching branches Changes files in the directory Deleting branch $ git branch –d <branch> Notice no -b here
12
git most useful! (aka advanced)
$ git init $ git clone <path/url> $ git status $ git diff <file> $ git add <file(s)> $ git commit $ git mv <old> <new> $ git rm <file> $ git log $ git remote -v|add|rm $ git fetch <remote> $ git push <rmt> <brnch> $ git branch <brnch> $ git checkout git most useful! (aka advanced) Merging Opposite of branching (sort of!) Get back to the branch you want new changes in $ git checkout master Call merge $ git merge myNewBranch Resolve conflicts if any Because the commit C4 pointed to by the branch hotfix you merged in was directly ahead of the commit C2 you’re on, Git simply moves the pointer forward When you try to merge one commit with a commit that can be reached by following the first commit’s history, Git simply moves the pointer forward Calling merge will create a new snapshot that results from the 3 way merge. The pointer to master is moved to the 3 way merged snapshot Git checks and uses the best common ancestor for its merge 3Wmerge: It turns a manual conflict into an automatic resolution. VCS locates the original version of the file. The VCS then passes the common ancestor and the two contributors to the three-way merge tool that will use all three to calculate the result. Info on 3-way merge:
13
git most useful! (aka advanced)
$ git init $ git clone <path/url> $ git status $ git diff <file> $ git add <file(s)> $ git commit $ git mv <old> <new> $ git rm <file> $ git log $ git commit –amend $ git reset HEAD <file> $ git checkout -- <file> $ git remote -v|add|rm $ git fetch <remote> $ git push <rmt> <brnch> $ git branch <brnch> $ git checkout $ git merge git most useful! (aka advanced) Merge conflict Resolve marked conflicts Add file to staging area $ git add README.md Commit the changes $ git commit
14
Working with large projects
Distributed development E.g. Working on some open source project on Github E.g. Multiple people working on the same project in CS2103 Example workflow: Fork Fork Pull request Main Project Repository Developer 2 Remote Repository Developer 1 Remote Repository Upstream Clone Pull Clone Read only Write Developer 2 Local Repository Developer 1 Local Repository
15
CS2103 Admin Matters
16
Project phases Two phases A and B Two different teams Experience
17
Project expectation Have a target user – specific user
One big feature per person – graded Cohesion necessary Eye candies ≠ features Any number of small features – graded differently! No morphing necessary; incremental updates
18
Every week Some deliverable Incremental
Counts for Phase A and Phase B points
19
Deliverables Individual vs Team Individual ⇒ Team
Team = Individual + Something
20
Tutorials Sign up if you haven’t done (Ideally 16 people)
Team formation next week T1 (Thursday )
21
Doing the right things Doing the things right
22
Necessary evil! Take care of the admin stuff
23
Thank you!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.