dhminh1024
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: Git Practice tags: CoderSchool, git, github --- ![](https://i.imgur.com/0AUxkXt.png) # Git Practice <p style='color:#95a5a6;font-weight:bold'>Easy - Common</p> <p style='color:#2980b9;font-weight:bold'>Beginner - Rare </p> <p style='color:#8e44ad;font-weight:bold'>Intermediate - Epic</p> <p style='color:#e74c3c;font-weight:bold'>Advanced - Legendary</p> Scenarios or problem statements: 1. <p style='color:#95a5a6;font-weight:bold'>How to create an Github repository?</p> * Create a new repository on the command line: ```bash= echo "# project_name" >> README.md git init git add README.md git commit -m "first commit" git remote add origin https://github.com/link_to_github_repo git push -u origin master ``` * Push an existing repository from the command line: ```bash= git remote add origin https://github.com/link_to_github_repo git push -u origin master ``` 2. <p style='color:#95a5a6;font-weight:bold'>How to push your code to Github repo?</p> ```bash= git push -u origin <branchName> ``` 3. <p style='color:#95a5a6;font-weight:bold'> What is staging, commit?</p> STAGING sets selected file in directory to tracked status and ready to commit. COMMITTING creates a snapshot of your directory at a particular moment 4. <p style='color:#95a5a6;font-weight:bold'> How to get code from repo?</p> ```bash= git pull origin branch_name # or git fetch origin branch_name git merge branch_name ``` 5. <p style='color:#95a5a6;font-weight:bold'> How to create a branch?</p> ```bash= git branch <newBranch> # or create and switch to the new branch git checkout -b <newBranch> ``` 6. <p style='color:#95a5a6;font-weight:bold'> How to switch to another branch?</p> ```bash= git checkout <nameBranch> ``` 7. <p style='color:#95a5a6;font-weight:bold'> How to merge?</p> ```bash= git checkout <nameBranch> git merge <anotherBranchname> ``` 8. <p style='color:#95a5a6;font-weight:bold'> How to rebase?</p> ```bash= # 1 checkout to the branch that you want to rebase git checkout <nameBranch> # 2 select the location you want to rebase. git rebase <nameBranch or commit hash> ``` 9. <p style='color:#8e44ad;font-weight:bold'>What is difference between merge and rebase?</p> `git merge` apply all unique commits from branch A into branch B in one commit with final result `git merge` doesn’t rewrite commit history, just adds one new commit `git rebase` gets all unique commits from both branches and applies them one by one `git rebase` rewrites commit history but doesn’t create extra commit for merging 10. <p style='color:#95a5a6;font-weight:bold'> How to move code to staging?</p> ``` git add . # add everything in your dir to staging area(except files in .gitignore) git add file_name # add only ``` 11. <p style='color:#95a5a6;font-weight:bold'> How to unstage code?</p> ``` git reset ``` 12. <p style='color:#2980b9;font-weight:bold'>How to get rid of changes that we don't want to commit?</p> ``` git stash ``` 13. <p style='color:#2980b9;font-weight:bold'>How to reapply stashed change?</p> ``` git stash apply or git stash pop ``` 14. <p style='color:#95a5a6;font-weight:bold'> How to commit code?</p> ``` git commit -m "Your message" ``` 15. <p style='color:#2980b9;font-weight:bold'>How to undo commit?</p> ``` git reset <commit> --soft: changed files are unstaged --hard: changed files are discarded ``` 16. <p style='color:#2980b9;font-weight:bold'>How to customize commits history? </p> ``` git rebase -i ``` 17. <p style='color:#95a5a6;font-weight:bold'>How to revert a specific commit? </p> ``` git revert <commit> ``` 18. <p style='color:#8e44ad;font-weight:bold'>What is the difference between reset and revert?</p> RESET moves the HEAD to a specific commit while REVERT records a new commit to reverse the effect of an earlier commit. 19. <p style='color:#95a5a6;font-weight:bold'>How to view commit log? </p> ``` git log or git reflog ``` 20. <p style='color:#2980b9;font-weight:bold'>How do we un-merged a master branch that has already been merged with another branch? </p> ``` git revert HEAD^ #can use head or <commit hash> or git reset HEAD^ #can use head or <commit hash> ``` 21. <p style='color:#8e44ad;font-weight:bold'>How do we undo rebase command?</p> Since rebase paste all the commits of a branch to the tip of another branch, we need refer to the reflog to find the change before the rebase. This is also the reason why we should not use revert, since revert only add nodes to the trees and not seperate the two branches to their original state. ``` git reflog # find the <commit hash> ``` then we reset it to the specified commit ``` git reset <commit hash> ``` 21. <p style='color:#2980b9;font-weight:bold'>What is the golden rule of rebasing? Explain it!</p> “Never rebase while you’re on a public branch". This change the tree history, which is catastrophic when multiple Dev working on it. [See more ](https://www.freecodecamp.org/news/git-rebase-and-the-golden-rule-explained-70715eccc372/) 22. <p style='color:#bdc3c7;font-weight:bold'> List the workflow of git. </p> - Directory - Staging - Commit ![](https://i.imgur.com/9hZ7kTO.png) 23. <p style='color:#e74c3c;font-weight:bold'>What is the different between reset and revert. When should we use revert or reset?</p> ``` git reset --soft <commit hash> # unstaged the changes you make. #Branch move to the specified commit (head must not be untached) git reset --hard <commit hash> # remove all the changes (like you never staged these changes) #Branch move to the specified commit (head must not be untached) git revert <commit hash> # clone the specified commit and add it to the tree ``` 24. <p style='color:#e74c3c;font-weight:bold'>If I rebase bugFix branch on top of my master branch, how can I move my master branch to the latest bugFix commit? Name at least two way to do it. </p> ``` # First method # if not on master branch git checkout master git rebase bugFix # Second method git checkout master git merge bugFix # Third method git checkout master git branch -f master bugFix ``` 25. <p style='color:#8e44ad;font-weight:bold'>How do we pull and push from a directory without enter username and password again? (only list the step) </p> ### Steps: 1. Check existing key 2. If not exist, generate your key 3. Copy the content of your key 4. Go to you github account add your key in 5. Testing for connections and allow to connect 6. Change your origin to use SSH connetion instead of HTTPS to clone repo. ### Details step-by-step: - Generate your own SSH key. ``` ssh-keygen -t rsa -b 4096 -C "your_email@example.com" ``` - When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location. ``` Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter] ``` - It will ask you to select a passphrase to protect your SSH key. ``` > Enter passphrase (empty for no passphrase): [Type a passphrase] > Enter same passphrase again: [Type passphrase again] ``` - Copy the content of your PUBLIC ssh key (Do not touch your private key) ``` clip < ~/.ssh/id_rsa.pub # if not working, use cat and copy everything from the terminal cat < ~/.ssh/id_rsa.pub ``` - Go to settings on your github account, choose SSH and GCP key option. Click on new SSH key and paste the key in. Remember to put a name for the device that you generate the key from. - Testing your SSH connection: ``` $ ssh -T git@github.com # Attempts to ssh to GitHub ``` - You may see a warning like this. Please enter yes to continue with the setup. ``` > The authenticity of host 'github.com (IP ADDRESS)' can't be established. > RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. > Are you sure you want to continue connecting (yes/no)? ``` - If this message pop up, you have succeeded ``` > Hi username! You have successfully authenticated, but GitHub does no provide shell access. ``` - Now set your connection to SSH to pull from you repo. The default connection is HTTPS, hence it requires you to enter username and password everytime. The SSH connection can be found on the clone button on your repo and it looks something like this: ``` git remote set-url origin git@github.com:dhminh1024/ml_question_bank.git ``` ## Customizing Gits * Open configuration file ```bash= vim ~/.gitconfig ``` * Configurations: ``` ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully