Skip to content

Latest commit

 

History

History
303 lines (211 loc) · 5.62 KB

git-usage.md

File metadata and controls

303 lines (211 loc) · 5.62 KB

git usage


github fork workflow ( using vscode )

Don't fork a project until you made some effective changes locally to the original cloned repository, instead:

  • clone project which you want to contribute
git clone REPO_URL
  • make changes locally and test them
  • create a branch named ( eg. fix-some ) with Source Control / Branch / Create Branch... or
git checkout -b fix-some
  • commit changes to your local branch
  • FORK the project using github btn then copy your forked repository url ( MY_ORIGIN ) to clipboard
  • add your origin from Source Control / More Actions / Add Remote... ( paste your fork url then insert a name my )
  • push changes to your repo Source Control / Push ( this will ask you to choose an origin as upstream of the branch fix-some, then choose your fork origin my )
  • go to github on your forked repository and click Compare & pull request btn

rename branch

sometime you need to import a local git repo to a remote where the default branch differs in the name, ie. local is master while in remote is main; to overcome this issue rename the branch before push

git branch -M main

checkout a remote branch

if remote not available adds ( REMOTENAME could "original" if you working on a fork and wants to add the original one )

git remote add REMOTENAME URL

then fetch the branch you need

git fetch REMOTENAME TAG

for a list of branches available locally use git branch -a

then checkout remote branch

git checkout -b remotes/REMOTENAME/TAG

graphical diff

apt install -y diffuse

edit ~/.gitconfig

[diff]
    tool = diffuse

and optionally to disable confirm open gui

[difftool]
    prompt = false

graphical diff ( code )

tune ~/.gitconfig

[merge]
    tool = vscode

[mergetool "vscode"]
    cmd = code --wait $MERGED

[diff]
    tool = vscode

[difftool "vscode"]
    cmd = code --wait --diff $LOCAL $REMOTE
    prompt = false

diff from previous commit

git diff commitid^!

to increase line numbers

git diff -U10 commitid^!

for latest commit diff

git diff HEAD^

undo last commit

git reset HEAD~

commit all staged files

commit -a -m "msg"

clone specific tag

git clone <url> --branch <tag> --single-branch

show local changes

git diff

show commit logs

git log

change to another branch/commit

git checkout <commit>

revert a commit

git revert <commit>

pick a commit

this will bring given commit and inject into current HEAD

git cherry-pick <commit>

pick some file from another commit

git checkout <COMMIT_SHA> -- filepath1 filepath2

discard all local changes

git clean -dfx

tag specific commit and push to remote

git tag -a vxxx <commit>
git push --tags

github tips

  • retrieve current page in a permalink form ( hotkey y )

show branches tree

prerequisite : apt install git-extras

git-show-tree

show local branches

git branch

sorted by recent

git branch --sort=-committerdate

or tree

git log --graph --pretty=oneline --abbrev-commit

commit to a new branch

git checkout -b newbranch
git add --all
git commit -a -m "msg"

merge a branch into current

git merge anotherbranch

delete branch local and remote

git branch -d branchname

to delete branch on remote:

git push originname --delete branchname

pull and switch to a branch

git fetch origin
git checkout --track origin/<branchname>

add submobule

for example follow initialize a submodule for given repo url and branch into local subfolder inside a thirdy folder

mkdir thirdy
git submodule add -b avalonia-pkg-upgrade https://github.com/SearchAThing-forks/CSharpMath.git thirdy/CSharpMath

submobule init

git submodule update --init

or if need to update submodule present in submodule ( use with caution, may not necessary )

git submodule update --init --recursive

reset head on remote

git reset --hard SHA
git push origin BRANCH --force