Git Commands Flashcards
What is Git?
A version control system
Software that tracks and manages changes to files over time
Repository
A workspace which tracks and manages files in a folder
git status
Checks if I’m in a git repo and commits
also can announce if and what file has made changes
working tree clean means it’s up to date
git init
Initializes empty Git repository in chosen folder (start) - hidden - one per project
rm -rf .git
This will remove your entire git history for the project
git add Chapter1.txt
If seen modified we can use add command and group together to get ready to commit
Can be one file or multiple
save point - staging area - stage file to be committed
git commit -m “my message”
This is like a checkpoint of process of your text/code
This will name the checkpoint easy
git log
This show a log of the commits for a given repository
This will show the author,date and commit messages
git add .
This will stage all changes at once which is all files at once being worked on
Add what you missed then
git commit - - amend
To redo a commit message update if you made a mistake one commit ago
touch .gitignore
This creates a new file that will hide files or directories to save your hidden codes or and frameworks/libraries
git branch
List the current branches in the repository
git branch bugfix
This will create a new branch it can be best to create this in a new folder
~mkdir BugFixes
git switch Done or /git checkout
This will switch to this branch for the meantime
git switch -c Done
This will create a new branch and switch over all at once
git branch -D Done
Must be on a different branch and this will delete a branch
git branch -m Main/ git commit -a -m Dn
Must be on current branch
This will change the name of the current branch including the default branch
git merge bugfix
This will merge with another branch
git diff
List all the changes in the working directory shows the differences in txt/code
git stash / git stash save
This helps you save changes that you are not yet ready to commit
git stash pop
To remove the most recently stashed changes
git stash apply
This will apply whatever is stashed away
git restore - - source HEAD~1 app.js
git reset <commit-hash> /
git reset hard <commit-hash></commit-hash></commit-hash>
Reset a repo back to a specific commit
git revert
git - - amend
To edit and change last commit message