Skip to main content

Git

Table of Contents

Submodule
#

Commit
#

  1. Add date and time in commit messages:
git commit -m "$(date '+%Y-%m-%d %H:%M:%S')"

Remote
#

Check the remote url:

git remote -v

If the remote url existing, set a new one:

git remote set-url origin <new_remote_address>

A Trick: you can connect your local repo to 2 remote repos:

git remote add public  https://<git_domain>/<username>/project-public.git
git remote add private https://<git_domain>/<username>/project-private.git

Branch
#

List all branches:

git branch -a

Move to a specific branch, the branch where you are currently working is marked with an asterisk (*):

git checkout <branch_name>

Create a new branch and switch to it:

git checkout -b <new_branch_name>

Push
#

Let us break down the push command:

git push origin main

, where origin is the remote name and main is the branch name. If you want to push to a different remote or branch, just replace them accordingly.

More advanced usage:

git push <remote_name> <local_branch_name>:<remote_branch_name>

There are no articles to list here yet.