Why Git?
● Most Operations are local● High integrity - use of SHA-1 hash● Most of the time, git adds data
○ Hard to mess up○ You can recover quite a bit○ All is not lost!
Git Configs
user.email user.namecore.editor merge.toolcolor.ui color.diffformat.signoff … and many, many more!See git help config
Initializing and Adding to Repos
● git init○ creates .git directory○ nothing is initially tracked
● git add○ Adds files/paths to a git○ can also use wildcards
● git clone○ git clone url [-b branch] [target]
Checking the file status
● git status● .gitignore● git diff● Exercise: demonstrating the lifecycle, pt 1
○ Creating○ Tracking○ Staging○ Committing
Viewing past changes
● git log○ -p switch - view code diffs for each commit○ -[#] (ex. -2) - view the past # commits○ --stat - view stats for each commit○ --pretty - format log
■ oneline■ format
○ --graph○ --name-only
Log --pretty=format: options%H,%h Commit hash
%T,%t Tree hash
%P,%p Parent hashes
%an Author name
%ae Author e-mail
%ad Author date (format respects the --date= option)
%ar Author date, relative
%cn Committer name
%ce Committer email
%cd Committer date
%cr Committer date, relative
%s Subject
Git to the rescue! Preventing derps
● git commit --amend● git reset HEAD <filename>● git checkout -- <filename>
Hint: Look at the git status command for clueson what to do next!
Using remote repositories - git remote● By itself - lists the remotes by short name
○ “origin” when cloned● -v option shows expanded URL● git remote add <shortname> <url-to-repo>● git remote set-url <shortname> <url>● git remote show <shortname>● git remote rm <shortname>● git remote rename <shortname>
The fetch/push cycle
● git fetch <shortname>○ Fetches all the branches/commits from the remote
● git pull <shortname> <branch>○ Shorthand merge (more on this later)
● git push <shortname> <branch>○ Pushes local commits to the remote
Cool git shortcut!
● aliases using git config○ git config --global alias.<shortname> <command>○ Ex: git config --global alias.co checkout○ git config --global alias.unstage ‘reset HEAD --’○ git config --global alias.last ‘log -1 HEAD’
Creating Branches
● git branch <branchname> - create branch● git checkout <branchname> - switch to
existing branch● git checkout -b <branchname> -
combination of git branch and git checkout
Resolving merge conflicts
● Choose one section or another or groups of either/both depending on what conflicts
● Requires a little knowledge & intuition● Git status tells all!<<<<<<< HEAD<div id="footer">contact : [email protected]</div>=======<div id="footer"> please contact us at [email protected]</div>>>>>>>> iss53
Branch management
● git branch○ git branch -v see the last commit on each branch○ git branch --merged find out which branches have
merged○ git branch --no-merged○ git branch -d / git branch -D delete branch