There are some git commands I often forget. Fuck that. I will write a cheatsheet to remember them.
1. Create a Upstream Remote
Here is the case. You have your local repository LA
, connected to your remote repository RA
, which is forked from RB
, the community upstream repository.
But now you want to connect LA
to RB
with your local git, so that pulling from RB
will be possible.
First, check existing remotes:
|
|
Next, add RB
as a remote, naming it, for example, upstream
:
|
|
Verify that the new remote has been added:
|
|
Then, fetch the branches and commits from upstream
:
|
|
Create a local branch upstream-dev
to track upstream/dev
:
|
|
Create the corresponding remote branch in your RA
:
|
|
Next time when you want to pull the changes from RB/dev
to RA/upstream-dev
, you can do:
|
|
2. I Forgot to Clone a Branch
This is very disgusting.
If you clone a repository with --branch <branchname>
, git will only clone that branch, and you cannot see other branches with git branch -a
.
Check your remote config:
|
|
This means that git will only fetch main
branch from remote origin
.
To fix this, run:
|
|
Then you can see all branches with git branch -a
.
Switch to your target branch:
|
|