Skip to content

Commit

Permalink
📝 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Alecton4 committed Aug 11, 2023
1 parent 43d577d commit 789ca27
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 144 deletions.
142 changes: 136 additions & 6 deletions notes-OS/cross-platform/git.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Git Configuration

This note contains configuration related tips. See [[notes-development/git]] for other git operation tips.
# Git Usage Tips

- [Local configuration](#local-configuration)
- [Show configs](#show-configs)
Expand All @@ -9,11 +7,23 @@ This note contains configuration related tips. See [[notes-development/git]] for
- [Specify how to reconcile divergent branches](#specify-how-to-reconcile-divergent-branches)
- [GitHub configuration](#github-configuration)
- [Add SSH key to GitHub](#add-ssh-key-to-github)
- [Commit message convention](#commit-message-convention)
- [Change commit messages](#change-commit-messages)
- [Clone to a specific directory](#clone-to-a-specific-directory)
- [Embedded repo](#embedded-repo)
- [Update an unchecked-out local branch from remote branch](#update-an-unchecked-out-local-branch-from-remote-branch)
- [Discard unstaged changes](#discard-unstaged-changes)
- [Stash changes](#stash-changes)
- [Rename branch](#rename-branch)
- [Change remote origin](#change-remote-origin)
- [Hard reset remote branch](#hard-reset-remote-branch)
- [Private fork](#private-fork)
- [墙国专属](#墙国专属)
- [Change `hosts`](#change-hosts)
- [Set proxy](#set-proxy)
- [Linux](#linux)
- [Other methods](#other-methods)
- [Interesting posts](#interesting-posts)

## Local configuration

Expand All @@ -36,7 +46,7 @@ Use `git config --global core.autocrlf false` or edit the `gitconfig` file direc

### Specify how to reconcile divergent branches

Use `git config --global pull.rebase false` to suppress this warning:
Use `git config --global pull.rebase false` to suppress the following warning:

```log
hint: You have divergent branches and need to specify how to reconcile them.
Expand Down Expand Up @@ -64,7 +74,119 @@ fatal: Need to specify how to reconcile divergent branches.
### Add SSH key to GitHub

1. Generate a key. See [[SSH#Generate SSH key]].
2. Refer to [the GitHub guide](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account).
2. See [the GitHub guide](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account).

## Commit message convention

*References*:

- [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)

## Change commit messages

- Change the last one: `git commit --amend`
- [ ] Change multiple

*References*:

- [Changing a commit message](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/changing-a-commit-message)

## Clone to a specific directory

Use `git clone [email protected]:SOME_REPO TARGET_DIRECTORY`.

*References*:

- [How do I clone a Git repository into a specific folder?](https://stackoverflow.com/questions/651038/how-do-i-clone-a-git-repository-into-a-specific-folder)

## Embedded repo

*References*:

- [Git: How to make outer repository and embedded repository work as common/standalone repository?](https://stackoverflow.com/questions/47008290/git-how-to-make-outer-repository-and-embedded-repository-work-as-common-standal)

## Update an unchecked-out local branch from remote branch

Use `git fetch REMOTE_REPO REMOTE_BRANCH:LOCAL_BRANCH`.

*References*:

- [How to 'git pull' into a branch that is not the current one?](https://stackoverflow.com/questions/18994609/how-to-git-pull-into-a-branch-that-is-not-the-current-one)

## Discard unstaged changes

- Discard all: `git restore .`
- Discard a specific file: `git restore PATH_TO_THE_FILE`

*References*:

- [How To Completely Reset a Git Repository (Including Untracked Files)](https://www.howtogeek.com/devops/how-to-completely-reset-a-git-repository-including-untracked-files/)

## Stash changes

- Stash changes by `git stash`.
- Pop stash by `git stash pop`.

*References*:

- [Git stash](https://www.atlassian.com/git/tutorials/saving-changes/git-stash)

## Rename branch

- Rename checked-out local branch: Use `git branch --move NEW_BRANCH_NAME`.
- Rename unchecked-out local branch: Use `git branch --move BRANCH_NAME NEW_BRANCH_NAME`.

## Change remote origin

Use `git remote set-url REMOTE_NAME NEW_URL`.

*References*:

- [How To Change Git Remote Origin](https://devconnected.com/how-to-change-git-remote-origin/)

## Hard reset remote branch

After hard resetting the local repo, use `git push -f REMOTE_REPO BRANCH_NAME` to hard reset the remote repo.

## Private fork

1. Create a new repo (`PRI_REPO`) via the GitHub Website.
2. Duplicate the public repo (`PUB_REPO`) via the following commands:

```bash
git clone --bare https://github.com/exampleuser/PUB_REPO.git
cd PUB_REPO.git
git push --mirror https://github.com/yourname/PRI_REPO.git
cd ..
rm -rf PUB_REPO.git
```

3. Clone the private repo and add `upstream` via the following commands:

```bash
git clone https://github.com/yourname/PRI_REPO.git
cd PRI_REPO
git remote add upstream https://github.com/exampleuser/PUB_REPO.git
git remote set-url --push upstream DISABLE # Optional
```

- Pull updates from `upstream` via the following commands:

```bash
git pull upstream master # Creates a merge commit
```

- Push to `PRI_REPO`:

```bash
git push origin master
```

*References*:

- [GitHub: How to make a fork of public repository private?](https://stackoverflow.com/questions/10065526/github-how-to-make-a-fork-of-PUB_REPOsitory-private)
- [Create a private fork of a public repository](https://gist.github.com/0xjac/85097472043b697ab57ba1b1c7530274)
- [Duplicating a repository](https://docs.github.com/en/repositories/creating-and-managing-repositories/duplicating-a-repository)

## 墙国专属

Expand All @@ -77,6 +199,10 @@ Get `hosts` from the following sites:
- https://ineo6.github.io/hosts/
- https://github.com/isevenluo/github-hosts

*References*:

- [修改 Hosts 解决 Github 访问失败马克](https://zhuanlan.zhihu.com/p/107334179)

### Set proxy

#### Linux
Expand All @@ -85,14 +211,18 @@ Get `hosts` from the following sites:

- [Configure Git to use a proxy](https://gist.github.com/evantoli/f8c23a37eb3558ab8765)
- [Configure Git to use a proxy (https or SSH+GIT)](https://gist.github.com/ozbillwang/005bd1dfc597a2f3a00148834ad3e551)
- [Git设置代理服务器](https://blog.csdn.net/yanhanhui1/article/details/118769098)

### Other methods

*References*:

- https://github.com/dotnetcore/FastGithub

## Interesting posts

- [git里面的文件怎么删不掉_彻底删除git中没用的大文件](https://blog.csdn.net/weixin_33335559/article/details/112012325)

[//begin]: # "Autogenerated link references for markdown compatibility"
[notes-development/git]: ../../notes-development/git.md "Git Tips"
[SSH#Generate SSH key]: remote/SSH.md "SSH Usage"
[//end]: # "Autogenerated link references"
File renamed without changes.
10 changes: 5 additions & 5 deletions notes-OS/cross-platform/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ type: index
- [[cross-platform/git]]
- [[vscode]]
- [[fonts]]
- [[hard_disk]]
- [[hard-disk]]
- [[NVIDIA]]

[//begin]: # "Autogenerated link references for markdown compatibility"
[shell]: ../Linux/cross-distro/shell-tools.md "Shell Related"
[terminal]: ../Linux/cross-distro/terminal-tools.md "Terminal Related"
[shell-tools]: ../Linux/cross-distro/shell-tools.md "Shell Related Tools"
[terminal-tools]: ../Linux/cross-distro/terminal-tools.md "Terminal Related Tools"
[remote/index]: remote/index.md "Remote Development"
[cross-platform/git]: git.md "Git Configuration"
[cross-platform/git]: git.md "Git Usage Tips"
[vscode]: VSCode.md "Visual Studio Code Tips"
[fonts]: fonts.md "Fonts"
[hard_disk]: hard_disk.md "Hard Disk Manipulation"
[hard-disk]: hard-disk.md "Hard Disk Manipulation"
[NVIDIA]: NVIDIA.md "NVIDIA Devices"
[//end]: # "Autogenerated link references"
2 changes: 1 addition & 1 deletion notes-development/Docker.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Develop Docker Application
# Docker Application Development
5 changes: 5 additions & 0 deletions notes-development/Java.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Java Development

## Readings

- [成为一个更好的Java程序员](https://github.com/crisxuan/bestJavaer)
127 changes: 0 additions & 127 deletions notes-development/git.md

This file was deleted.

6 changes: 3 additions & 3 deletions notes-development/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ type: index
## General tips

- [[notes-development/tips]]
- [[notes-development/git]]

## Programming languages

- [[C]]
- [[CPP]]
- [[Flutter]]
- [[Java]]
- [[LaTeX/index]]
- [[Python]]
- [[Rust]]
Expand All @@ -28,16 +28,16 @@ type: index

[//begin]: # "Autogenerated link references for markdown compatibility"
[notes-development/tips]: tips.md "General Development Tips"
[notes-development/git]: git.md "Git Tips"
[C]: C.md "C"
[CPP]: CPP.md "C++"
[Flutter]: Flutter.md "Flutter"
[Java]: Java.md "Java Development"
[LaTeX/index]: LaTeX/index.md "$\LaTeX$"
[Python]: Python.md "Python"
[Rust]: Rust.md "Rust"
[Scala]: Scala.md "Scala"
[decentralization]: decentralization.md "Decentralization Related"
[ML]: ML.md "Machine Learning"
[Android]: Android.md "Android"
[notes-development/Docker]: Docker.md "Develop Docker Application"
[notes-development/Docker]: Docker.md "Docker Application Development"
[//end]: # "Autogenerated link references"
4 changes: 2 additions & 2 deletions notes-development/tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

## Git commit message convention

See [[notes-development/git#Commit message convention]].
See [[cross-platform/git#Commit message convention]].

[//begin]: # "Autogenerated link references for markdown compatibility"
[notes-development/git#Commit message convention]: git.md "Git Tips"
[cross-platform/git#Commit message convention]: ../notes-OS/cross-platform/git.md "Git Usage Tips"
[//end]: # "Autogenerated link references"

0 comments on commit 789ca27

Please sign in to comment.