Git global setup

1
2
git config --global user.name "Your Name"
git config --global user.email "your.name@example.com"

Create a new repository on the command line

1
2
3
4
5
6
7
echo "# template" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:Chasing66/template.git
git push -u origin main

Push an existing repository from the command line

1
2
3
git remote add origin git@github.com:Chasing66/template.git
git branch -M main
git push -u origin main

gitconfig

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[include]
path = /etc/git-setup/gitconfig
[core]
editor = vim
[user]
name = Your Name
email = your.name@example.com
[merge]
tool = vimdiff
[alias]
co = checkout
ci = commit
st = status
br = branch
hist = log --graph --format=format:\"%C(red)%h%C(reset) %C(yellow)%cd%C(reset) | %s %C(green)\\[%an\\]%C(reset)%C(bold blue)%d%C(reset)\" --abbrev-commit --date=short
root = rev-parse --show-toplevel
alias = !git config --list | grep ^alias
head = rev-list -n1 --abbrev-commit HEAD
l = log --stat --color --graph --pretty=format:'%C(bold red)%h%C(reset) - %C(bold green)(%cr)%C(bold blue)<%an>%C(reset) -%C(bold yellow)%d%C(reset) %s' --abbrev-commit
[init]
defaultBranch = main
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true

Syncing a fork branch from the command line

1
2
3
4
5
6
7
8
9
10
11
git remote -v
git remote add `origin-repo-alias` `origin-repo-address`

git fetch `origin-repo-alias` `origin-repo-branch-name`

git merge `origin-repo-alias/origin-repo-branch-name`

# For example
git fetch upstream
git merge upstream/main
git push

Push from local branch to remote main

1
2
3
4
5
6
7
8
9
fatal: The upstream branch of your current branch does not match
the name of your current branch. To push to the upstream branch
on the remote, use

git push origin HEAD:main

To push to the branch of the same name on the remote, use

git push origin HEAD