Crash-course on Git & GitHub

Notes on Git and GitHub

Ikechuku Ukpa
3 min readMar 29, 2021

What is Git?

Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. (source: https://git-scm.com/doc)

Git Sample Commands

git init
git add
git commit -m ‘insert comment here’
git status
git diff
git rm — cache
git — version
git config — global user.name ‘john doe’
git config — global user.email ‘doe@yahoo.com

git clone: Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change

git add: Add file contents to the index
mv Move or rename a file, a directory, or a symlink

git reset: Reset current HEAD to the specified state

git rm: Remove files from the working tree and from the index
examine the history and state

git bisect: Use binary search to find the commit that introduced a bug

git grep: Print lines matching a pattern
log Show commit logs

git show: Show various types of objects

git status: Show the working tree status
grow, mark, and tweak your common history

git branch: List, create or delete branches

git checkout: Switch branches or restore working tree files

commit: Record changes to the repository

diff: Show changes between commits, commit and working tree, etc

merge: Join two or more development histories together

rebase: Reapply commits on top of another base tip

tag: Create, list, delete or verify a tag object signed with GPG collaborate

fetch: Download objects and refs from another repository

pull: Fetch from and integrate with another repository or a local branch

push: Update remote refs along with associated objects

‘git help -a’ and ‘git help -g’ list available subcommands and some
concept guides.

‘git help <command>’ or ‘git help <concept>’
to read about a specific subcommand or concept.

Using .gitignore

create git ignore file :
touch .gitignore

add files to be ignored to .gitignore
log.txt (ignore log.txt)
/dir2 (ignore directory dir2)
*.txt (ignore all text files)

Branching

git branch newbranch
git checkout newbranch

Merge the newbranch to the Master
git merge newbranch

Git and GitHub

Git can keep track of changes made to code, synchronize code between different people, test changes to code without losing the original, and revert back to old versions of code.
GitHub is a website that stores Git repositories on the internet to facilitate the collaboration that Git allows for. A repository is simply a place to keep track of code and all the changes to code.

Git commands examples (usage):

— git clone <url>: take a repository stored on a server (like GitHub) and downloads it
— git add <filename(s)>: add files to the staging area to be included in the next commit
— git commit -m “message”: take a snapshot of the repository and save it with a message about the changes
— git commit -am <filename(s)> “message”: add files and commit changes all in one
— git status: print what is currently going on with the repository
— git push: push any local changes (commits) to a remote server
— git pull: pull any remote changes from a remote server to a local computer
— git log: print a history of all the commits that have been made
— git reflog : print a list of all the different references to commits
— git reset — hard <commit>: reset the repository to a given commit
— git reset — hard origin/master: reset the repository to its original state (e.g. the version cloned from GitHub)

- When combining different versions of code, e.g. using git pull, a merge conflict can occur if the different versions have different data in the same location. Git will try to take care of merging automatically, but if two users edit, for example, the same line, a merge conflict will have to be manually resolved.
— To resolve a merge conflict, simply locally remove all lines and code that are not wanted and push the results.

GitHub Pages

- GitHub Pages is a feature of GitHub which allows for a repository to be deployed to the internet.
- Simply scroll to GitHub Pages under Settings, select the master branch, and click save.
- By default, the repository will be deployed to username.github.io/repository.
- GitHub Pages is automatically updated when the repository is updated.

--

--