Basic Git Commands

Some must-knows

Basic Git Commands
  • Git clone with token if the repo is private or need specific access
git clone https://<USERNAME>:<TOKEN>@github.com/<OWNER>/<REPOSITORY>.git
  • Git global setup
git config --global user.name example_user
git config --global user.email [email protected]
  • Git to store credentials in plaintext in a file (not recommended)
git config --global credential.helper cache
git config --global credential.helper store
  • Create a new repository
git clone http://git.example.com/example_user/some-project.git
cd some-project
git switch -c main
touch README.md
git add README.md
git commit -m "add README"
git push -u origin main
  • Push an existing folder
cd existing_folder
git init --initial-branch=main
git remote add origin http://git.example.com/example_user/some-project.git
git add .
git commit -m "Initial commit"
git push -u origin main
  • Push an existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin http://git.example.com/example_user/some-project.git
git push -u origin --all
git push -u origin --tags
  • If you like to use mobile App for GitLab. You can try GitBlur on AppStore. Access Token is required. Go to User Settings -> Access Tokens -> Select scop and generate token.

Copyright statement: Unless otherwise stated, all articles on this blog adopt the CC BY-NC-SA 4.0 license agreement. For non-commercial reprints and citations, please indicate the author: Henry, and original article URL. For commercial reprints, please contact the author for authorization.