Skip to main content

Basic setup & Commands

Add your information​

It is for the first time use.

The user's email:

git config --global user.email "[email protected]"

The user's name:

git config --global user.name "Chieh"  

Clone​

SSH method

git clone (ssh://-)

Or HTTP/HTTPS method

git clone (https://~)

Remote setup​

Basically we will need to use this "git remote" command to control all actions regarding the remote repository.

  1. First of all, we can use git remote -v to check this git folder connecting to where?

    ➜ git remote -v
    origin [email protected]:chiehpower/test.git (fetch)
    origin [email protected]:chiehpower/test.git (push)

    It means the remote address of the "Origin" this source will connect to [email protected]:chiehpower/test.git this remote repository.

    Note: Normally, we could see "origin" this source for most of articles. It is just a name to represent the following repository path. Of course, we can name it as what we want. That's all.

    For example, we can add many remote sites like below.

    ➜ git remote -v
    origin [email protected]:chiehpower/test.git (fetch)
    origin [email protected]:chiehpower/test.git (push)
    github [email protected]:chiehpower/test.git (fetch)
    github [email protected]:chiehpower/test.git (push)

    We can choose which remote source we wanna push to and fetch from.

  2. You will need to set a remote repository at least.

    Command:

    git remote add <name> <url>

    The <name> represents a remote source name.

    For eaxmple:

    git remote add origin [email protected]:chiehpower/test.git  
  3. Push the codes to different multiple registries at the same time.

    Command:

    git remote set-url --add <upstream> <url>

    Let's check original remote-name.

    git remote -a

    For example:

    $ git remote -a
    origin [email protected]:chieh/test.git (fetch)
    origin [email protected]:chieh/test.git (push)

    Assume that I have another repository on Gitlab, and I want to update the code at the same time. It means when I push the codes to Github (origin) in the future, it will help me directly push the codes to GitLab.

    git remote set-url --add origin [email protected]:chieh/test.git

Reset​

git reset --hard HEAD^

worktree​

Worktree is somewhat similar to git stash, but sometimes git stash can easily cause more problems due to operational mistakes.

In simple terms: Git creates a new folder (workspace) where only the operations related to that branch are performed. You can make changes inside this folder and then discard the folder (workspace) afterward.

git worktree list​

Check the workspace of a worktree list.

git worktree add​

Command:

git worktree add <folder name> <branch name>

For example:

git worktree add dev dev

`git worktree remove <folder/workspace name>​

git worktree remove dev