3.9 KiB
Basics
-
https://www.nobledesktop.com/learn/git/git-branches
Git Branches_ List, Create, Switch to, Merge, Push, & Delete (11_2_2023 4_41_42 PM).html
-
Branches
-
If you want to push your code to a different branch of the remote repository on Codeberg, you can specify the branch in the git push command. Here's how you can do it:
Assuming you have already added the remote repository using a command like:
git remote add origin your-codeberg-repo-url.gitYou can push your code to a different branch as follows:
git push origin your-local-branch-name:your-remote-branch-nameHere's what each part of the command does:
your-local-branch-name: Replace this with the name of the local branch you want to push. This is the branch that contains the code you want to deploy. your-remote-branch-name: Replace this with the name of the branch in the remote repository (on Codeberg) where you want to push your code.For example, if you have a local branch called "feature-branch" and you want to push it to a branch named "production" on Codeberg, you would use the following command:
git push origin feature-branch:productionThis command will push the code from your local "feature-branch" to the "production" branch on the remote repository on Codeberg. Make sure the branch names are accurate to avoid any conflicts or errors. to change default branch
git push -u origin --all
-
-
undo git add For specific files use
git reset <file>For all filesgit reset HEAD -
diff When using diff and we wanna avoid the changes in whitespace bcz of pretty formatting then use
git diff -worgit diff -w --numstatWhen using diff filemode ie permissions is different by default in windows and unix machines so when using git diff output can beold mode : 100644 new mode : 100755So to fix it use
git config core.filemode falsehttps://stackoverflow.com/questions/1257592/how-do-i-remove-files-saying-old-mode-100755-new-mode-100644-from-unstaged-cha -
pull requests
- after cloning the repo(original one) and cd into it fetch the pull request to branch named 'local-branch-name'. name can be anything.
git fetch origin pull/PR_NUMBER/head:local-branch-name - Then switch to
local-branch-nameand check it, if changes are good then merge it bygit checkout main # or develop, or another branch git merge local-branch-name
- after cloning the repo(original one) and cd into it fetch the pull request to branch named 'local-branch-name'. name can be anything.
-
to list all files tracked by github use
git ls-files -
to push non interactively use this found this, this is the way
git push https://$GIT_USERNAME:$GIT_TOKEN@github.com/username/repo.git
to have different user and email for repo use this
git config user.name "Your Work Name"
git config user.email "work@email.com"
clearing .git folder
sometimes git folders can become very large. few things to clear is
to check issues or dangling blobs(uncommited files/data to repo)
git fsck --full
and to remove dangling blobs
git prune
but if it got commited then for untracking
git rm -r --cached bin/
git rm -r --cached obj/
and for actual removing
# using filter branch
git filter-branch --force --index-filter \
"git rm --cached --ignore-unmatch path/to/bigfile.zip" \
--prune-empty --tag-name-filter cat -- --all
# Clean up refs and gc
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now --aggressive
# Force push
git push origin --force --all
git push origin --force --tags
instead of filter branch, this can be used too, though it needs to be installed pip install git-filter-repo --break-system-packages
git filter-repo --path path/to/bigfile.zip --invert-paths
**applying patches **
from a file
git apply --check ytfetch-403-fix.patch
If it doesn't return anything, that's good.
then
git apply ytfetch-403-fix.patch
create patch with
git diff > my_patch.patch