Git and Github Flashcards
Learn Git and Github, Colt Steel Udemy course
Who created Git and why
Linus Torvalds. He wanted a free VCS (Version Control System)
What is Git
Git is a Version Control System. A Version Control System tracks changes to project files over time.
Explain the 3 states a file can be in
Working directory/tree
Staging area
Committed to repo
What is the command to check git file statusses and what does it report?
git status
when on a given branch. It displays the status of each file that is not yet committed, ie staged or in working directory.
It also reports the status of the branch, things like if the head is detached and how many commits the local branch is ahead of origin (remotes)
Added, removed, modified in staging area and working tree/directory
What is the command to move a file to the staging area?
git add example.txt example2.text
git add .
- add all files from working directory.
What is the command to commit staged files?
git commit -m “some message”
git commit - opens vim or default editor in order to enter message.
How can you check the commits on a branch?
Go to the branch and run git log
How can you see commits on a branch, but compressed to a single line per commit?
git log –oneline - currently checked out branch
How can you see commits on a branch, but as a graph
git log –graph : currently checked out branch
How do you create a git repo
git init command
OR
create on Github/Gitlab/Bitbucket and clone
What is a git repo
A project that git should track history of file changes for over time.
What is an untracked file
A file not yet committed or staged, in working directory
What should commit messages look like
Git itself suggests present tense. Some people prefer past tense.
What does the HEAD refer to
By default it refers to the tip of the currently checked out branch. The tip is the latest commit.
If the head is detached it refers to a specific commit on the checked out branch.
When the head is detached, all the files in your local project will be what it was at the point where that commit was done. Inclusive of changes in the commit.
Explain commit relationships
Each commit has a sha1 hash as an id. The next commit has a reference to the parent’s hash.
In the context of a merge commit, the commit has 2 parent commits
What are atomic commits
Files that do a single thing grouped together as a single commit, that is, staged and then committed together.
What are the benefits of atomic commits
If you have to revert for example, then a single thing could be reverted, and not things unrelated to the revert.
How do you tell git to ignore files and folders
Add a .gitignore file
Files: example.txt
Folders : some-folder/
Explain amending commits
You can amend the most recent commit by adding the –amend flag to a commit (git commit)
You can stage and unstage files
You can write a new git commit message - either with -m flag or set default editor.
How can you see all branches
git branch
- local branchesgit branch -r
- remote branches
How do you switch to other branch
git switch example-branch
git checkout example-branch
How to delete git branch
Must be on other branch
git branch -d the-branch
git branch -d the-branch –force OR git branch -D the branch if the branch not yet merged into a different branch.
Flags shortcuts vs regular
For the full flag use –, for example –delete
For shortcut use -, for example -d
How can you create a branch and switch to it immediately
git switch -c new-branch
git switch –create new-branch
git checkout -b new-branch
When a new branch is created, what is it created from?
By default it is created from HEAD. That means it’s created from the checked out branch OR the commit that HEAD refers to if it’s detached.
How do you rename a branch
When on the relevant branch run
git branch -m new-name OR
git branch –move new-name