github Flashcards
What is cloning?
Copying the repository from GitHub.com to your local machine.
Command to clone a repo.
git clone
Proper use of git clone
Create a new folder & cd into it. Then use git clone with the repo’s url.
What is a remote?
A url where a repo pushed up to. Basically just the url where the repo exists online.
Command to view a list of any existing remotes in your repo.
git remote or git remote -v (verbose for more info)
Command to add a new remote.
git remote add (name is usually origin)
Command to push code to github.
git push
Command to push a local branch to a remote branch with a different name.
git push origin name1:name2
Command to rename master to main.
git branch -M main
What is a remote tracking branch?
The last time you communicated with a particular remote repo, this is a pointer that points to the most recent changes on that repo’s master branch. So it’s basically a bookmark which shows the most recent change on the main branch from the origin.
Command to see where remote tracking branch currently is.
git branch -r
Command to see what your project looked like when you cloned it from github.
git checkout origin/main
Command to get the online repo up to date with your local machine.
git push origin main
When you clone a repo, by default it is connected to origin/master. If you want to switch to another branch you use the ________ command.
git checkout /origin/branchname
Command to create a new local branch from the remote branch of the same name.
git switch (This will set the branch up to track the remote branch origin/remoteBranchName. So it basically creates a new branch and automatically connects it to main in the same way that the original branch is)
What is fetching?
When a remote repo you’re working with gets updated and you want to get the updates from it.
When you fetch, where does the code from the remote repo go?
Directly into your local repo. It does not automatically merge those changes into your local repo.
Command to fetch branches & history from a specific remote repo.
git fetch
Command to fetch fetch just one branch from a remote.
git fetch
What is pulling?
Retrieves changes and actually updates our HEAD branch with whatever changes are retrieved from the remote. So it automatically updates your working directory with the new changes.
Pulling is similar to combining which two operations?
fetch & merge
Command to pull from a remote branch.
git pull
Where are the changes merged to when pulling?
Whichever branch the command is run from.
Command to pull the latest code from origin’s master branch and merge those changes into our current branch.
git pull origin master