Some basics about Git and GitHub.
Although there are many tutorials online, I still want to record some of them here for my own reference.
1
2
|
git config --global user.name "Your Name Here"
git config --global user.email "your_email@youremail.com"
|
NOTE: your_email@@youremail.com
should be the noreply
email address of your GitHub account.
Set the global .gitignore
file:
1
|
curl https://raw.githubusercontent.com/github/gitignore/master/Global/macOS.gitignore -o ~/.gitignore
|
Config git
to use the global .gitignore
file:
1
|
git config --global core.excludesfile ~/.gitignore
|
visit gitignore to generate a .gitignore
file for your project.
1
2
|
git clone https://github.com/<username>/<repo-name>.git # https
git clone git@github.com:<username>/<repo-name>.git # SSH
|
1
|
git branch <branch-name>
|
1
|
git checkout <branch-name>
|
or
1
|
git switch <branch-name>
|
Create and switch to a new branch
1
|
git checkout -b <branch-name>
|
or
1
|
git switch -c <branch-name>
|
First, switch to the branch you want to merge into, for example, main
:
Then, merge the branch you want to merge into main
, for example, dev
:
1
|
git branch -d <branch-name>
|
If the branch has not been merged, use -D
instead of -d
:
1
|
git branch -D <branch-name>
|
Make sure you have generated an SSH key pair on your local machine.
See GitHub documents