Walkthrough: Git and Gitlab
Follow along with the instructor as we review Git and Gitlab.
We will be using Git, and GitLab almost everyday throughout this class. This walkthrough will show you some of the basics. Primarily creating new projects, creating new branches, creating merge requests for branches, and resolving merge conflicts.
Setup
- You will need a Gitlab account (don’t worry it’s free)
- Go to gitlab.com
Follow Along as we…
Part 1 - Instructor Steps
- The instructor will create a new project on Gitlab for this walkthrough
- Instructor will add a file to the repo using a branch and a Merge Request
- In your terminal, clone that repo
- Create a new branch. Example: blakes-branch
- Checkout the new branch
- Creat a new file that includes your name in the filename. Example: blake.txt
- Stage and commit your change
- Push your branch to origin
- Go to gitlab.com and create a Merge Request for your branch
- Have another student merge your Merge Request
- Checkout master locally
- Do a get pull to see your changes now in master
Part 2
- The instructor will create a new branch that incluedes a roster.txt file
- That branch will be merge into master
- Everyone in the class should pull to get the commit containing that file
Note
Instructor should do these next steps first
- Create and switch to a new branch
- Add your name to the roster.txt file
- Stage, commit, and then push their changes
- You should get a merge conflict
- Resolve the conflict by editing the file that has the conflict
- Run git status in terminal
- Run git add roster.txt to mark the conflict as resolved
- After resolving your conflicts you can push your changes to origin
Git Reference
Switch to an Existing Branch
git fetch
to make sure you have an updated list of branches
git branch -a
show a list of all existing branches
git checkout BRANCH-NAME
will checkout the branch BRANCH-NAME
Create a New Branch
git status
to make sure you are on the branch you want to make a branch from
git checkout -b NEW-BRANCH-NAME
creates branch NEW-BRANCH-NAME and switches to it
Commit and Push
How to commit and push your changes to a remote repo.
git status
to review branch and files that have changed
git add .
stage your changes
git commit -m "a short message about what you changed"
git push
push commit to remote repo
Other Helpful Commands
git log
see list of commits on your current branch
git pull
pull in the latest changes for your current branch from origin
git fetch
make your local repo aware of any new changes on origin
git reset --hard
WARNING!! Removes all local changes that have NOT been committed