Presentation is loading. Please wait.

Presentation is loading. Please wait.

Git branches and remotes

Similar presentations


Presentation on theme: "Git branches and remotes"— Presentation transcript:

1 Git branches and remotes
Landon Cox February 2, 2017

2 Basic terminology and overview
Commit Object pointing to a snapshot Named by hash and stored as a tree Commits have parents that point to the previous snapshot Branch Pointer to a commit (and its snapshot) e.g., “master” Remote Collection of branches stored on a remote server e.g., a gitlab or github project

3 Basic terminology and overview
Commit Object pointing to a snapshot Named by hash and stored as a tree Commits have parents that point to the previous snapshot Branch Pointer to a commit (and its snapshot) e.g., “master” Remote Collection of branches stored on a remote server e.g., a gitlab or github project

4 What are these funny hex numbers?
A commit and its tree What are these funny hex numbers? $> git add README test.rb LICENSE $> git commit -a -m “Initial commit”

5 Why will the commit hash change if I modify a file?
A commit and its tree Why will the commit hash change if I modify a file? $> git add README test.rb LICENSE $> git commit -a -m “Initial commit”

6 A commit and its tree $> git add README test.rb LICENSE
best $> git add README test.rb LICENSE $> git commit -a -m “Initial commit”

7 Commits and their parents
What do I need to move from one commit to another?

8 Basic terminology and overview
Commit Object pointing to a snapshot Named by hash and stored as a tree Commits have parents that point to the previous snapshot Branch Pointer to a commit (and its snapshot) e.g., “master” Remote Collection of branches stored on a remote server e.g., a gitlab or github project

9 A branch and its commit history

10 Two branches w/ same commits
$> git branch testing

11 HEAD pointing to master branch
$> git log --oneline --decorate f30ab (HEAD -> master, testing) add … 34ac2 Fixed bug # stack overflow … 98ca9 The initial commit of my project

12 HEAD pointing to testing branch
$> git checkout testing

13 A new commit under testing
$> vi test.rb $> git commit -a -m “made a change”

14 Checking out master $> git checkout master

15 A new commit under master
Given the diffs I have, can I integrate my testing changes into master? $> vi test.rb $> git commit -a -m “another change”

16 Merging branches

17 Merging branches $> git branch iss53 $> git checkout iss53
$> git checkout -b iss53

18 Merging branches $> vi index.html
$> git commit -a -m “added a new footer [issue 53]”

19 Merging branches $> git checkout master
$> git checkout -b hotfix $> git commit -a -m “fixed broken link”

20 Merging branches $> git checkout master $> git merge hotfix

21 Merging branches $> git branch -d hotfix $> git checkout iss53
$> vi index.html $> git commit -a –m “finished footer [issue 53]”

22 Merging branches

23 Merge commit: special commit created from three-way merge
Merging branches Merge commit: special commit created from three-way merge $> git checkout master $> git merge iss53

24 Merging branches Sometimes merges fail due to conflicts
Git cannot create the diffs to move one commit to another Often due to multiple changes to the line in a file $> git merge iss53 Auto-merging index.html CONFLICT (content): Merge conflict in index.html Automatic merge failed; fix conflicts and then commit the result.

25 Edit files to manually resolve the conflict.
Merging branches Sometimes merges fail due to conflicts Git cannot create the diffs to move one commit to another Often due to multiple changes to the line in a file Edit files to manually resolve the conflict. $ git status On branch master You have unmerged paths. (fix conflicts and run "git commit") Unmerged paths: (use "git add <file>..." to mark resolution) both modified: index.html no changes added to commit (use "git add" and/or "git commit -a")

26 Inside the conflicted file (index.html in example)
Merging branches Sometimes merges fail due to conflicts Git cannot create the diffs to move one commit to another Often due to multiple changes to the line in a file <<<<<<< HEAD:index.html <div id="footer">contact : ======= <div id="footer"> please contact us at </div> >>>>>>> iss53:index.html Inside the conflicted file (index.html in example)

27 Content in master branch (since HEAD pointed to master during merge)
Merging branches Sometimes merges fail due to conflicts Git cannot create the diffs to move one commit to another Often due to multiple changes to the line in a file Content in master branch (since HEAD pointed to master during merge) <<<<<<< HEAD:index.html <div id="footer">contact : ======= <div id="footer"> please contact us at </div> >>>>>>> iss53:index.html Content in iss53 branch

28 Content of conflicted file after manual resolution.
Merging branches Sometimes merges fail due to conflicts Git cannot create the diffs to move one commit to another Often due to multiple changes to the line in a file <div id="footer"> please contact us at </div> Content of conflicted file after manual resolution. (i.e., kept the iss53 content, removed <<<, ===, and >>> lines)

29 Merging branches Sometimes merges fail due to conflicts
Git cannot create the diffs to move one commit to another Often due to multiple changes to the line in a file Once conflict has been resolved, add and commit $> git add index.html $> git commit

30 Rebasing branches

31 Basic terminology and overview
Commit Object pointing to a snapshot Named by hash and stored as a tree Commits have parents that point to the previous snapshot Branch Pointer to a commit (and its snapshot) e.g., “master” Remote Collection of branches stored on a remote server e.g., a gitlab or github project

32 Remote branches “origin” = default name of remote repo
“master” = branch of remote repo

33 Equivalent commands to clone.
Remote branches Equivalent commands to clone. $> mkdir project $> cd project $> git init $> git remote add origin $> git fetch origin $> git merge origin/master

34 “origin” is local name for this remote
Remote branches “origin” is local name for this remote $> mkdir project $> cd project $> git init $> git remote add origin $> git fetch origin $> git merge origin/master

35 fetch retrieves data for remote merge remote/branch into local repo
Remote branches fetch retrieves data for remote merge remote/branch into local repo $> mkdir project $> cd project $> git init $> git remote add origin $> git fetch origin $> git merge origin/master

36 Can name remote whatever you want,
Remote branches Can name remote whatever you want, e.g., “jane” $> mkdir project $> cd project $> git init $> git remote add jane $> git fetch jane $> git merge jane/master

37 “git pull” is shorthand for fetch and merge
Remote branches “git pull” is shorthand for fetch and merge $> mkdir project $> cd project $> git init $> git remote add origin $> git fetch origin $> git merge origin/master

38 “git pull” is shorthand for fetch and merge
Remote branches “git pull” is shorthand for fetch and merge $> mkdir project $> cd project $> git init $> git remote add origin $> git pull origin master

39 Note that because pull merges, it can lead to conflicts
Remote branches Note that because pull merges, it can lead to conflicts $> mkdir project $> cd project $> git init $> git remote add origin $> git pull origin master

40 “git remote –v” prints all the remotes you’ve linked
Remote branches “git remote –v” prints all the remotes you’ve linked $> mkdir project $> cd project $> git init $> git remote add origin $> git remote –v

41 “git remote rm” removes a remote
Remote branches “git remote rm” removes a remote $> mkdir project $> cd project $> git init $> git remote add origin $> git remote rm origin

42 How to work with your group project


Download ppt "Git branches and remotes"

Similar presentations


Ads by Google