Yet Another Git Primer

What is Git and why should I use it?

Motivation: Checkpoints

https://imgs.xkcd.com/comics/git.png
https://imgs.xkcd.com/comics/git.png
All comics have been borrowed from https://xkcd.com/

Copying a repo — clone

Creating a repo — init

Staging — add

Commit — commit

Receive — fetch/pull

Conflicts

Send — push

Conflicts

! [rejected] master -> master (fetch first) 
error: failed to push some refs to 'https://github.com/mrmechko/repo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

A sample branching paradigm

Creating branches — branch

Exploratory — checkout

Conflicts!

This line does not have a conflict. 
<<<<<<< main
this line has a conflict.
=======
This line is a conflict.
>>>>>>> other-branch;
This line does not have a conflict. 
this line has a conflict.
This line does not have a conflict. 
This line is a conflict.

Pull Requests

Temporary — stash

UNDO! UNDO!! — revert

Some strategies to avoid panic.

Commit messages

Work on your own branch

Test before you merge

Avoiding Conflicts

Help, I need to remove a file from the repository!

Help, I staged a file for commit but I don’t want to commit it!

CS Professor, AI/NLP Researcher

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store