Things to remember GIT Flashcards
How to create a new Git repository
git init
How to inspect the contents of the working directory and staging area?
git status / gst
How to add files from the working directory to the staging area?
git add
How to show the difference between the working directory and the staging area?
git diff
How to permanently store file changes from the staging area in the repository?
git commit -m “message”
How to show a list of all previous commits?
git log / git lg
How to discard changes in the working directory?
git checkout HEAD filename
How to unstages file changes in the staging area?
git reset HEAD filename
How to reset to a previous commit in your commit history?
git reset commit_SHA (7-first-digits of the commit)
How to add all files at once to the stage?
git add .
How to temporarly save/retrieve files in order to switch branches without loosing everything?
git stash
git stash pop
How to update your previous commit?
create your changes, stage them with git add and then type the command git
commit –amend
How to set up an alias for each command?
git config –global alias.co “checkout” (co becomes checkout)
How to move Files in the terminal?
mv file.txt destinared_directory
How to rename files in Terminal?
mv file.txt newFile.txt
Open VS Code from Terminal?
code .
How to delete files from the terminal?
rm file.txt
How do you create a local branch?
With git checkout -b new-branch-name.
myproject git:(master) git checkout -b new-branch-name
myproject git:(new-branch-name)
Be careful, always check the branch you currently are on before creating a new branch.
Most of the times you’ll want to be on master with the up-to-date version of master before starting a new feature.
To do so, git checkout master, git pull origin master and THEN create your new branch.
How do you resolve a merge conflict with the command line?
On the laptop of the owner of the unmergeable branch:
git checkout master
git pull origin master
git checkout my-unmergeable-branch
git merge master
Then you solve conflicts locally (you can cmd + shift + f ‘»»»’ to find them quickly).
In your terminal:
git add .
git commit -m “conflict solving”
git push origin my-unmergeable-branch
Refresh your PR on GitHub, you can now merge your branch!
How do you create a repo on GitHub?
gh repo create –public –source=.
How do you print the list of local and remote branches in your terminal?
git branch -a
How do you clone an existing GitHub repo on your computer?
fork the repo on github.com
under code copy the SSH adress
git clone ‘ssh-adrress.git’
How do you generate your User model using devise?
rails g devise User
How to switch to a diffrent hard drive in bash?
cd /D (Capital Letter for the Drive)
How to delete a project and it’s files in the terminal?
rm -rf my-project
How to merge a branch into main?
git merge branch-name
How to delete a branch?
git branch -d branch-name
How to list all branches?
git branch
How to create a new branch?
git branch branch-name
How to switch from one branch to another?
git checkout branch_name
How to merge origin/master into your local
branch?
git merge origin/master
A common Git collaboration workflow is?
- Fetch and merge changes from the remote
- Create a branch to work on a new project feature
- Develop the feature on a branch and commit the work
- Fetch and merge from the remote again (in case new commits were made)
- Push branch up to the remote for review
Steps 1 and 4 are a safeguard against merge conflicts, which occur when two branches contain file changes that cannot be merged with the git merge command.