Git & GitHub Flashcards
(24 cards)
What’s a version control system? And how do we classify Git?
A VSC is a way of handling with multiple versions of a document, creating a way of ‘time traveling’ through these versions.
GIT is a distributed version control system.
What’s the difference between Git and GitHub?
Github is just a place where we can store our git repositories.
How do you configure your git to add your name and email?
git config –system user.name “name of person”
git config –system email@email.com
How to initialize a git repo?
on the directory you want to version control:
git init
What are the 3 stages a file can be?
1 - untracked
2 - on stage (goes on the next commit)
3 - commited (ready to push)
How do you change branches?
git checkout branch_name
or to create and go:
git checkout -b newBranchName
How do you list you current branches?
git branch
How to delete a branch?
git branch -D
How to see how is the status of your repository?
git status
How to add a file to the “on stage” state?
git add file
How to commit a change to the staged files?
git commit -m “msg of commit”
How to upload your changes to your github repo?
git push -u origin master
This pushed your master branch to the remote repo
-u flag sets the upstream so we can use just ‘git push’ after that
How to add the URL of the remote repo?
git remote add origin “http/ssh url”
“origin” here is the nickname of our repo
How to check the current URL of our remote repo?
git remote -v
How to clone a repo?
git clone repo_url
Will create a directory on the pwd that will hold the project cloned
How to check the logs of a project? And for a specific file?
git log
specific file:
git log file_name
How to see the modifications done in a commit? And how to check just the last commit?
git show commit_hash
If you do just git show you list just the last commited changes.
How to remove/rename/move a file on a git repo? Why?
git rm/git mv
We do this because if we do the normal rm/mv way the change will have to be commited to work on the remote repo, this way its done already and the next push will update the remote repo automatically.
And by doing so, if we delete a file we can later recover it.
How do you ignore a file/directory to not upload it?
Create a .gitignore file on source folder and add the path to the file/directory you want to ignore. ONE PER LINE!
Like
node_modules/
src/passwords/
How to remove from the project a file/folder you added but it should be on gitignore?
Execute
git rm -r –cached file_name
add them to .gitignore
git add .gitignore
git push
How to delete a remote branch?
git push origin –delete branchName
How to fetch and merge the remote changes to the local project? And if we want to do it separetely?
git pull
sep: git fetch + git merge
How to do a good Pull Request? (PR)
- clone project
- create your branch
- make changes
- git push -u origin yourBranchName
- On github open the PR and click Compare, making sure you are comparing the master to your branch
- Add a descriptive title + description
- Make sure to describe each commit you do after that
Should we work on the master branch?
NOOOOO!!!