Derived from: https://github.com/PortAudio/portaudio/wiki/UsingTheGitRepository
Official Git reference: https://www.git-scm.com/docs/
git status
If your main branch is named master
:
# sync local master branch with upstream repo master branch:
git checkout master
git pull origin
git fetch upstream master
git merge upstream/master
git push origin master
If your main branch is named main
:
# sync local main branch with upstream repo main branch:
git checkout main
git pull origin
git fetch upstream main
git merge upstream/main
git push origin main
# make a new branch and develop on it:
git checkout -b <new branch name>
git add ...
git commit -m...
# first push:
git push --set-upstream origin <new branch name>
# or equivalently
git push --set-upstream origin HEAD
# or equivalently (needs recent git)
git push --set-upstream-to HEAD origin
# or, since git>=2.37.0, do this once:
git config --add --bool push.autoSetupRemote true
# then
git push origin
# subsequent pushes:
git add ...
git commit -m...
git push origin
Use the GitHub website to fork the upstream project repo into your personal GitHub account.
Prerequisite: Set up your fork for the first time above.
git clone https://github.com/{your_account}/portaudio.git
cd portaudio
ls
git remote -v
git remote add upstream https://github.com/PortAudio/portaudio.git
git remote -v
Prerequisite: Set up a local working directory for the first time above.
git checkout master
git pull origin
2. Sync your local working directory with upstream (i.e. upstream = official portaudio project repo)
git fetch upstream master
git merge upstream/master
git push origin master
Prerequisite: Sync your local working directory with origin and upstream above.
git checkout master
git checkout -b {the name of your new branch}
git status
git diff # (see "Diff your changes" section below)
git add {file names}
git commit -m"your commit message"
(DYOR)
The first time, use the command:
git push --set-upstream orgin {branch name}
GitHub will reply with a link for creating the PR.
Alternatively, since git>=2.37.0, do this once:
git config --add --bool push.autoSetupRemote true
Then you can push the first commit with:
git push origin
Then once you have set the upstream branch you can use the following for additional pushes:
git push origin
Note that if the upstream brach is not set, you can always do the following to push:
git push origin {branch name}
List branches:
git branch
Change to branch:
git checkout {branch name}
Delete a local branch:
git branch -D {branch name}
Diff current work area with changes already staged for commit:
git diff
Diff staged against most recent commit to current branch:
git diff --staged
Diff current work area (both staged and unstaged) with most recent commit to current branch:
git diff HEAD
You can diff a specific file by adding the file name to the end of any of the above commands:
git diff {file name}
You can diff between branches (with optional file name):
git diff {branch name a} {branch name b}
and between commits:
git diff {commit hash a} {commit hash b}
Save and restore uncommitted changes to the stash stack.
git stash [push]
git stash pop
https://www.git-scm.com/docs/git-stash
Add more files or changes to the most recent commit, with or without editing the commit message:
git add {file names}
git commit --amend -m "New and correct message"
or
git add {file names}
git commit --amend --no-edit
Amend only the commit message of the most recent commit:
git commit --amend -m "New and correct message"