Skip to content

Git

Reflog

git reflog
git reset --hard <reflog_id: HEAD@{2}>

Stash

git stash apply stash@{<index>}
git stash list
git stash drop stash@{<index>}
git stash clear
git stash pop stash@{<index>}
git stash show stash@{<index>}

Tag

# Without message
git tag <tag_name>

# with message
git tag <tag_name> -m "<message>"

# Add tag to specific commit
git tag <tag_name> <commit_id>
# Without message
git tag -f <tag_name> <commit_id>

# with message
git tag -f <tag_name> -m "<message>"
# Simple
git tag

# More verbose
git tag --list
# For local repo
git tag --delete <tag_name>

# For remote repo
git push origin --delete <tag_name>
git show <tag_name>
# Single tag
git push origin <tag_name>

# All tags
git push origin master --tags

Auth (SSH)

  1. Generate ssh key:

    ssh-keygen -t rsa
    
  2. Add private key to system by:

    ssh-add
    
  3. Get public ssh key by this command:

    cat ~/.ssh/id_rsa.pub
    
  4. Add public ssh key to git profile setting: https://github.com/settings/keys

  5. Change project remote URL, to ssh type
  6. Connect to git:

    ssh -T git@github.com
    

Auth (Token & In-URL Auth)

# With OAuth2
git clone https://oauth2:<access_token>@gitlab.com/myrepo.git

# With username
git clone https://<username>:<access_token>@gitlab.com/myrepo.git
git clone https://<username>:<password>@gitlab.com/myrepo.git
git+https://<username>:<access_token>@gitlab.com/myrepo.git@<tag>
git+https://<username>:<access_token>@gitlab.com/myrepo.git

Alias

git config --global alias.<command_name> "<command>"

# Example
git config --global alias.hist "log --all --oneline --graph --decorate"

Config

git config --global core.editor "<editor name: vim>"
git config --global credential.helper 'cache --timeout=<time in seconds: 3600>'
git config --global http.sslverify false

Pull/Push

stat -c %y .git/FETCH_HEAD