Skip to content

learicard/git-intro

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Git intro

This is a short practical introduction to collaborative Git fundamentals. For the theoretical part, see the slides.

Go get started:

  1. Create a GitHub account.
  2. Fork this repository.
  3. Install Git on your computer.
  4. Clone your forked repository:
git clone <your-repository-url>

Exercise 1: Commit

  1. Make a change in file_1.md.
  2. Check the status of the repository.
git status
  1. Check the changes made in the file.
git diff
  1. Add the file to the staging area.
git add file_1.md
  1. Commit the changes.
git commit -m "put a descriptive message here"
  1. Push your local changes to the remote repository.
git push

Exercise 2: Checkout

  1. Checkout to the previous commit.
git checkout HEAD~
  1. Look at the content of file_1.md. What do you see?
  2. Check your current position in the tree of commits, indicated by (HEAD).
git log --all --decorate --oneline --graph

Note: Instead of typing the long git log command every time, you can create an alias for it (here git lg):

git config --global alias.lg "log --all --decorate --oneline --graph"

Exercise 3: Branch

  1. Create a new branch from the commit of the previous exercise.
git branch new-branch
  1. List all the branches.
git branch
  1. Switch to the new branch.
git checkout new-branch
  1. Make a change in file_2.md.
  2. Commit your changes.
  3. Look at the current tree of commits.
git log --all --decorate --oneline --graph

Note: The git branch new-branch and git checkout new-branch commands can be combined into a single command:

git checkout -b new-branch

Bonus step: Try to push new-branch to the remote repository (origin). Note that new-branch does not exist on the remote repository yet.

Exercise 4: Merge

  1. Make sure that all changes are commited on new-branch. Running git status should show nothing to commit, working tree clean.
  2. Switch back to the main branch.
git checkout main
  1. Merge the changes from new-branch to main.
git merge new-branch
  1. Look at the current tree of commits.

Bonus Exercise: Merge Conflict

  1. Create a branch conflict-branch from main.
  2. Make a change in file_1.md in conflict-branch and commit it.
  3. Switch back to main and commit a different change in file_1.md that conflicts with the change commited in conflict-branch (e.g. change the same line).
  4. Merge conflict-branch to main and resolve the conflict.

Exercise 5: Pull Request

  1. Checkout to the main branch and push it to the remote repository.
  2. Go to the GitHub page of your forked repository.
  3. Create a pull request from your main branch to the original repository's main branch.
  4. Add the description and comments to the pull request.

Additional Resources

About

Practical introduction to collaborative Git fundamentals

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published