This article contains some useful git commands.

Commonly Used

File Changes

# Check file changes
$ git diff path/to/file
index 91c1227..6e48ccd 100644
--- a/hls/rocev2/rocev2_config.hpp.in
+++ b/hls/rocev2/rocev2_config.hpp.in
...

# Discard file changes
$ git checkout path/to/file

# Unstage all file changes
$ git checkout -- .

# Check commit history
$ git log
commit 442f822ebe205151c1538e08e53cd7cea2cbdd40
Author: terry <hcxxstl@gmail.com>
Date:   Wed Mar 31 23:28:49 2021 +0200

    update testbench debug

# Remove untracked files directories
$ git clean -fd

Account

# Set username globally
$ git config --global user.name "terry"

# Set email address globally
$ git config --global user.email "name@gamil.com"

# Cache credential so that you don't have to type it every time
$ git config credential.helper cache

Info

# Get repo URL
$ git config --get remote.origin.url
https://github.com/hcxxstl/fpga-network-stack.git

# More infomation
$ git remote show origin
* remote origin
  Fetch URL: https://github.com/hcxxstl/fpga-network-stack.git
  Push  URL: https://github.com/hcxxstl/fpga-network-stack.git
  HEAD branch: master
  Remote branches:
    master        tracked
    xilinx-tcp-ip tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

Submodule

# Show submodule info
$ git submodule status
4794e9cefef8aa6a1c984f9ed23de0249d7fb89d fpga-network-stack (heads/master)

# Clone/update submodules
$ git submodule update --init --recursive

# Add submodule from url to this repo
$ git submodule add https://github.com/hcxxstl/fpga-network-stack.git fpga-network-stack