More Git: Removing files from the repository Branches, tags, merge conflicts Pull requests CPSC 491 First: Get up to speed from last time Removing files from your workspace Use git rm to remove files from workspace e.g., to get rid of unneeded files when you push to origin/master, removes file there as well How to run: git rm FILE
Exercise 9: Add and remove a file 1. create a new file called YOURNAME-tmp.txt 2. add it to your workspace & push to origin/master 3. remove the file from your workspace 4. update and then push change Creating a branch You create a branch using git branch BNAME will want to branch from an update-to-date branch e.g., after pulling origin/master You switch to the branch using git checkout BNAME this sets your current workspace to the branch can switch back and forth between branches How to run: git branch BNAME git checkout BNAME Alternatively: git checkout -b BNAME
Exercise 10: Create a branch 1. create a new branch named YOURNAME-branch 2. create, add, and commit a file to the branch named YOURNAME-file-2.txt 3. switch to the master branch 4. what changed in your working directory (e.g., run ls)? Merging branches When you are in a branch, you can merge in another branch e.g., to update your branch, merge master into it or, switch to master, merge in your branch adds new files, merges changes to existing files Use the git merge BNAME to merge in changes How to run (e.g., from your new branch): git merge master -m message git merge origin/master -m message
Exercise 11: merge a branch 1. switch to master (git checkout master) 2. create, add, and commit a file to the branch named YOURNAME-file-3.txt 3. switch to your branch 4. merge in master (git merge master -m... ) 5. what changed in your branch? 6. switch back to master and push your changes... Pushing your new branch So far, you only have your branch in your workspace Now we want to push it to the mothership e.g., so that others can work on it and so it is versioned in the central repository To push it (from within the branch), run: git push --set-upstream origin BNAME
Exercise 12: push your branch 1. switch to your branch 2. push your branch 3. see if you can find your branch on GitHub To remove a branch Once you are done with a branch you can delete it either locally or from the repository To remove a branch locally run (from master): git branch -d BNAME To remove a branch from repository run (from master): git push origin --delete BNAME
Creating Tags Git supports 2 kinds of tags: lightweight vs annotated an annotated tag has additional information including a message and info on who created the tag To see the existing tags: git tag To create an annotated tag: git tag -a TAGNAME -m tag message To see information about a tag: git show TAGNAME Exercise 13: tag your branch 1. switch to your branch 2. create a tag with tag name v0.1 3. verify that the tag was created and show the tag info
Pushing Tags to the Shared Server By default, git push doesn t push tag information instead, have to tell git to push the tag To push a tag: git push origin TAGNAME To branch form a tag: git checkout -b BRANCHNAME TAGNAME This only creates a branch, tagged configurations don t change Exercise 14: push your tag 1. push your tag to origin 2. go onto GitHub 3. select branch & look at releases (should see your branch)
Merge Conflicts Usually git can auto-merge just fine But sometimes there is a problem when it can t merge a conflict, it pauses the merge process and then you have to fix the conflict yourself You can run a mergetool to help fix the merge: git mergetool Once the merge is resolved, start the process again git status will tell you what to do Exercise 15: resolve a conflict 1. switch to your branch 2. add Hello World! to the end of YOURNAME.txt 3. commit the file 4. switch to master 5. add Hellooo Wooorld!!! to the end of YOURNAME.txt 6. commit the file 7. switch to your branch and merge in master 8. fix the merge and commit 9. what happens to master?
Pull Requests A feature of GitHub... request for a branch to be pulled into master UI for carrying out this process Try it out: 1. make sure your branch is pushed 2. log on to GitHub, select your branch 3. click on the pull request button 4. walk through the steps of performing a pull request Where to find out more... The Git book: https://git-scm.com https://git-scm.com/book The GitHub documentation https://help.github.com