Git Flashcards
What is Git?
A distributed open-source version control system. You can work locally, then share or push your changes to a server (ex. GitHub or Gitlab)
main
the primary branch of all repositories.
branch
a version of the repository that diverges from the main working project. Branches can be a new version of a repo, experimental changes, or personal forks of a repository for users to alter and test changes.
fork
creates a copy of a repository.
merge
taking the changes from one branch and adding them into another.
“git clone LINK-HERE”
download an existing git repository to work on locally. git will download the entire repository (files and history). This only needs to be run once per repository since it creates a complete copy on your local machine.
Take the link from a remote repository (HTTPS). Then follow the flashcard “How to start a react repository?”
stage
you have marked a modified file in its current version to go into your next commit snapshot.
git add (command)
adds a change in the working directory to the staging area.
git commit -m “MESSAGE HERE” (command)
used to save your changes to the local repository. You normally want to group
git push (command)
updates a remote branch with local commits. the “-u” flag links the local branch with the remote branch, so the next time you can just use git push or pull without any arguments.
git status (command)
displays the state of the working directory and the staging area.
staging vs committing
The staging environment is where related modified files are added to a queue to be committed later. Committing captures a snapshot of the project’s currently staged changes. You want to stage related changes and then use commit to record those small changes. See the link for example: https://githowto.com/staging_and_committing
git pull
When you want to take changes or updates done by other developer/team member on git repository. “Git pull” fetches downloads the content from a remote repository and immediately updates the local repository/branch to match the content. In actuality, it is a combination of git fetch and git merge called in that order.
“git switch” (command)
switch between branches created by git branch. You can also use git checkout to switch branches.
“git log” (command)
View the history of committed changes within a git repository. To exit git log, type “q” or “z”. Type “h” to seek for help.
“git restore –staged FILE-NAME…” (command)
unstages the file.
“Head” branch
the currently “active” or “checked out” branch. Using “git status” will say what head branch- such as On branch …
About Branch
you can create branches on your local repository and then upload the branch onto a remote repository.
“git branch -m NEW-NAME” (command)
re-names the local head branch
“git branch” (command)
shows all branches. Adding BRANCH-NAME right after creates a new branch. To delete a local branch: “git branch -d BRANCH-NAME”. You cannot delete a branch if it is the HEAD branch. To delete a branch in a remote repo “git push REMOTE-NAME –delete BRANCH-NAME”. The remote name is typically origin. You can delete the local and then remote branch.
“git branch -m OLD-NAME NEW-NAME”
renames a local branch.
How to rename branches
You can rename branches in remote repositories. So you’ll need to delete the remote current/old branch by “git push origin –delete OLD-NAME” and then push the new local branch with the new name by “git push -u origin NEW-NAME”
Should I manage my repository remotely or locally?
You should manage your repository and branches locally. First, you should create a local repository and then publish it to the remote repository by “git push -u origin LOCAL-BRANCH”
Learn git branching
https://learngitbranching.js.org/?locale=en_US AND https://www.youtube.com/watch?v=e2IbNHi4uCI (git branch and merge)
merging branches
merges changes from another branch into your current local HEAD branch. 1. switch to the branch that should receive the changes using “git switch BRANCH-NAME”. 2. execute the merge command with the name of the branch that contains the desired changes using “git merge BRANCH-NAME”.
rebase branches
an alternative way to merging. The end result is the same, but the commit history will look like a straight line with no branches. 1. check out the branch that should receive the changes by “git switch BRANCH-NAME”. 2. execute the “rebase” command with the name of the branch that contains the desired changes using “get rebase BRANCH-NAME”
comparing branches
checks which commits are in branch-B but not in branch-A. Use “git log BRANCH-A BRANCH-B”. You can also compare remote branches to local branches.
git checkout
lets you switch between branches created by git branch. using “git checkout -b NEW-BRANCH” simultaneously creates a new branch and switches to the new branch
How to start a react repository?
in terminal, navigate to the directory and run “npm install” then “npm start”
git config -l
shows the git configuration list with the global user.name and user.email. use keys “j” or “k” to go up or down the list. Use “q” to quit the list.
SSH key
SSH keys are used for authenticating to a remote server, instead of authenticating using credentials. After generating an SSH key, the private and public keys will have the same name. The .pub file is the public key. In windows the SSH keys are normally stored in C:\Users\USERNAME.ssh
local repository name vs remote repository name
the local repo directory can be named different than the remote repo and still sync.
“git remote set-url origin REMOTE_URL”
Changes the URL of the remote origin.
how to push new Git branches to a remote repository
https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/git-push-new-branch-remote-github-gitlab-upstream-example
README.md cheatsheet
https://www.markdownguide.org/cheat-sheet/
upstream and downstream
upstream is the repository that we clone or pull from, or push to. Downstream is our local repository. These terms are relative, which means there is no central upstream or downstream. It depends on what the other repository is trying to do.
git fetch
This will download all the new changes from the remote repository but will not merge those changes into your local repository. This allows you to review the changes before merging (using “git merge”) them into your local repository.
git merge
This will merge the changes from “git fetch” into your local repository.
“git config –get remote.origin.url”
see remote git repository link