Leo Chu
    • 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
    # git basic ###### tags: `git` `revision control` -------------------------------- # Introduction ## fetch vs pull -------------------------------- # Git in MS-Windows ## `git clone` an Existing Repository in MS-Windows Normally `cd <repo_dir>; git clone <https_URL>/<project.git>` command is used in Linux to clone an existing online git archive to the local repository, however, CLI is not all that accessible in MS-Windows. Normally git-GUI or VSCode client is used to retrieve the git repository. ### `git clone` with ssh server *NOTE*: the ssh server must have git installed as `git clone` just uses ssh for transfer the git data. https://help.github.com/en/articles/which-remote-url-should-i-use SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and add the public key to your GitHub account. For information on setting up an SSH keypair, see "Generating an SSH key." When you git clone, git fetch, git pull, or git push to a remote repository using SSH URLs, you'll be prompted for a password and must provide your SSH key passphrase. If you are accessing an organization that uses SAML single sign-on, you won't be able to clone with SSH. Instead, clone with the HTTPS URL. Tip: SSH URLs can be used locally, or as a secure way of deploying your code to production servers. You can also use SSH agent forwarding with your deploy script to avoid managing keys on the server. If you use the alternate form of ssh URLs you don't need an absolute path. For example... git clone lars@myserver.example.com:repos/myrepo.git ...will clone repository repos/myrepo.git relative to my home directory, although this doesn't permit use of an alternate port. However, you can also use ~ in either form to indicate the user's home directory, e.g.: git clone ssh://login@server.com:12345/~/repository.git ### git-GUI/VSCode repo cloning from https_URL ### git-GUI/VSCode repo cloning from MS-Windows CIFS Shared Directory This does make the git cloning operation a bit strange. For example, the git repository sits on `\\nleids6500-transit-nas01.sn-eu.asml.com\HOME_SDEV$\lchu\leoscript\` CIFS shared directory and the backward slash must be translated into the forward slash, so that the cloning command becomes: `git clone //nleids6500-transit-nas01.sn-eu.asml.com/HOME_SDEV$/lchu/leoscript c:\Users\lchu\repo\leoscript` [Some people](https://stackoverflow.com/questions/2519933/git-clone-repo-across-local-file-system-in-windows/2520121) were saying `file://` notation shall be used instead. You can specify the remote’s URL by applying the UNC path to the file protocol. This requires you to use four slashes: `git clone file:////<host>/<share>/<path>` For example, if your main machine has the IP 192.168.10.51 and the computer name main, and it has a share named code which itself is a git repository, then both of the following commands should work equally: ``` git clone file:////main/code git clone file:////192.168.10.51/code ``` Leo: below is what works for me. `git clone --no-hardlinks /path/to/repo` The above command uses POSIX path notation for the directory with your git repository. For Windows it is (directory C:/path/to/repo contains .git directory): `C:\some\dir\> git clone --local file:///C:/path/to/repo my_project` The repository will be clone to C:\some\dir\my_project. If you omit `file:///` part then `--local` option is implied. ## Modify Files in git Repository git shall automatically track the changes you've made to the files that are currently in git repository. Unless it's a new file, then `git commit -a -m "your-comment"` shall just commit your changes to your local git repository. `git add -i` - add files to the local git repository interactively. ## Identify the Remote Repository Linked (OPTIONAL) A remote origin is automatically added when a local repository is `git clone` from a remote location. Anyway, multiple remote repositories can be defined in your local git repository. `git remote -v` - show all remote repositories that are currently linked to. Normally just one remote repository where the local repository is cloned from. `git remote add <remote_repo_name> <https_URL>` - add another remote repository to the existing git repo (for redundancy???) In VSCode, just launch a terminal open your git repository is opened. The terminal will automatically change the directory to your repository, then issue `git remote -v` command to identify the repo's remote(s). ``` C:\Users\lchu\repo\leoscript>git remote -v origin //nleids6500-transit-nas01.sn-eu.asml.com/HOME_SDEV$/lchu/leoscript (fetch) origin //nleids6500-transit-nas01.sn-eu.asml.com/HOME_SDEV$/lchu/leoscript (push) ``` ## Push Changes in The Local Repository to The Remote `git push <remote_repo_name> <branch>` - Push latest changes in your local repository to its remote, eg: `git push ORIGIN master`. `git push origin master:master` ``` git checkout master ``` (If you're on a different branch than master, use the branch name there instead.) If that doesn't work, try... For a single file: ``` git checkout HEAD /path/to/file ``` For the entire repository working copy: ``` git reset --hard HEAD ``` ### Push Problem Encountered Leo: When I tried to push changes stored on my laptop onto its origin (remote network files on my $HOME drive which has a slower access), the following error came up. I couldn't understand its problem as I have seen this type of problem in SCCS/CVS/Perforce before. At the end, I figured out it's due to the REMOTE repository is on the same branch as my LOCAL repository. To workaround this issue, just switch to a different branch on the remote repository. This is annoying. Maybe the best practice would be working on "lchu_dev" branch and constantly update my code to this branch (whenever there is a new incremental feature added OR at the end of day), then merge the changes to the HEAD when all features are completed and tested. This is philosophy of git: version control every incremental changes rather than one big BULK. ``` C:\Users\lchu\repo\leoscript>git push Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 8 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 346 bytes | 346.00 KiB/s, done. Total 3 (delta 2), reused 0 (delta 0) remote: Checking connectivity: 3, done. remote: error: refusing to update checked out branch: refs/heads/master remote: error: By default, updating the current branch in a non-bare repository remote: is denied, because it will make the index and work tree inconsistent remote: with what you pushed, and will require 'git reset --hard' to match remote: the work tree to HEAD. remote: remote: You can set the 'receive.denyCurrentBranch' configuration variable remote: to 'ignore' or 'warn' in the remote repository to allow pushing into remote: its current branch; however, this is not recommended unless you remote: arranged to update its work tree to match what you pushed in some remote: other way. remote: remote: To squelch this message and still keep the default behaviour, set remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'. To //nleids6500-transit-nas01.sn-eu.asml.com/HOME_SDEV$/lchu/leoscript ! [remote rejected] master -> master (branch is currently checked out) error: failed to push some refs to '//nleids6500-transit-nas01.sn-eu.asml.com/HOME_SDEV$/lchu/leoscript' ``` ## Pull vs Fetch When I tried to push the changes in my local repository to its remote, VSCode asked me about "Shall fetch be periodically performed at the background for you". This is interesting. Pull/Fetch will ensure my local repository is up-to-date before I push the changes. But where are the differences between Pull and Fetch? ----------------------------------- Reference [1] https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control <h1> Git Tagging </h1> https://git-scm.com/book/en/v2/Git-Basics-Tagging

    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