How to use git

Git

common usage of Git.

Author

Guofeng Lin

Published

November 20, 2023

View branches

# view remote address
git remote -v

# View all branches and the red branch represents the current branch.
git branch -a

# view git log
git log

# check what changes have been made in the current branch.
git status

View git configuration

git config --list

View tags

# to fetch tags from a remote repository
git fetch tags

# list all tags
git tag -l

# to switch your working derectory to the state of the repository at the time a specific tag was created
git checkout [target_tag]

# to display the current state of your repository's working directory and staging area.
git status

Push files to a remote repository

# add the file to upload
git add [your files]
# wirte your commit message
git commit -m [your commit]
# push to the remote repository
git push -u origin main

Push to a new GitHub repository from local repository

# initialization
git init
# add the file to upload
git add [your files]
# wirte your commit message
git commit -m [your commit]
# change the branch from master to main (if needed)
git branch -M main
# create a remote repository on Github
git remote add origin https://github.com/your_account/your_project.git
# push to the remote repository
git push -u origin main

Use proxy

# to set http proxy
git config --global http.proxy http://127.0.0.1:1080
# to set https proxy
git config --global https.proxy https://127.0.0.1:1080

# view http proxy configuration
git config --global --get http.proxy
# view https proxy configuration
git config --global --get https.proxy

# to unset http proxy
git config --global --unset http.proxy
# to unset https proxy
git config --global --unset https.proxy