Last active
September 26, 2024 12:48
-
-
Save josanua/d2e5096bda105053310c1e906cb7ef70 to your computer and use it in GitHub Desktop.
git
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://githowto.com/ | |
https://training.github.com/ | |
https://www.godaddy.com/help/use-git-to-manage-your-site-12067 | |
https://www.nobledesktop.com/learn/git/git-branches | |
// conventions | |
https://dev.to/varbsan/a-simplified-convention-for-naming-branches-and-commits-in-git-il4 | |
// explicatii simple despre Git | |
https://www.youtube.com/watch?v=Dw2FzMigkVU&t=4s | |
// de vizionat | |
https://github.com/josanua/login_system_oop_php.git | |
// !!! common git commands, general commands !!! | |
http://guides.beanstalkapp.com/version-control/common-git-commands.html | |
// probleme cu datele de acces existente pe MAC, Access Token | |
https://gist.github.com/jonjack/bf295d4170edeb00e96fb158f9b1ba3c | |
// sterge datele existente apoi cind faci clone/pull/push iti cere datele noi, trebuie sa faci token nou. | |
security delete-internet-password -l github.com | |
// Config | |
$ git config --global user.name "First Last" | |
$ git config --global user.email "[email protected]" | |
// helpuri | |
https://www.youtube.com/watch?v=2aTc37XwSj0 | |
// -- Essentials -- // | |
Git are 3 stari: | |
1. Fisierul creat | |
2. Git urmareste fisierele | |
3. Git a creat un punct de control | |
//-- config --// | |
# Running git config globally | |
$ git config --global user.email "[email protected]" | |
$ git config --global user.name "Brian Kerr" | |
# Running git config on the current repository settings | |
$ git config user.email "[email protected]" | |
$ git config user.name "Brian Kerr" | |
//-- initierea, lucru cu proiect --// | |
// 1.) in caz ca fac un proiect nou pe local | |
git init (initierea) | |
git config (https://githowto.com/setup) | |
//-- incarcare proiect de pe Github --// | |
2.) | |
git clone <repository URL> | |
git status | |
//-- statuses, Verify situation --// | |
git status | |
git diff (--staged) | |
// add to commit, add files | |
git add -A (sau -a adauga fisierele, -A toate, sau numefisier.extensie) | |
git commit -a -m "first commit" (-a toate fisierele, -m message) | |
// change github origin address | |
git remote set-url origin | |
// download project (fara git init) | |
git clone link | |
git pull (sa tragi de pe repozitoriu) | |
// rename project origin to exclude original files overwrite, change branches | |
1.) git remote rename origin upstream (upstream name how we wan't) | |
2.) git remote add origin https://github.com/josanua/guttenberg-text-box-block.git | |
3.) git remote -v (to check remote branch status) | |
4.) git add -A | |
5.) git commit -m "added needed files" | |
6.) git push -f origin main (force update if need it) | |
or do this | |
git pull origin main (master) | |
git push origin main (master) | |
//-- Verify situation --// | |
git log | |
git status | |
git show b8a23c688bc2529dfe5a7fc1dd43d956a2854f34 (hash, give detail information about changes) | |
git diff | |
git diff --staged (modificarile care sunt in index, adica gatite pentru commit) | |
git diff 166368b0d9a157206670ec51fc931ca5d352780d (hash) | |
// view conf. | |
git config -l | |
// Unset git config, remove git, sterge git din folder | |
rm -rf .git | |
rm -rf .git* (from all project) | |
//--> to do after created git repo <--// | |
// create local reppo andpush | |
// create a new repository on the command line | |
echo "# shopify-theme-dev" >> README.md | |
git init | |
git add README.md | |
git commit -m "first commit" | |
git branch -M main | |
git remote add origin https://github.com/josanua/shopify-theme-dev.git | |
git push -u origin main | |
// or push an existing repository from the command line | |
git remote add origin https://github.com/josanua/shopify-theme-dev.git | |
git branch -M main | |
git push -u origin main | |
// Or then do clone it will be initialiased by default | |
git clone | |
// first push of booilerplate-for-custom-WP-plugin | |
echo "# booilerplate-for-custom-WP-plugin" >> README.md | |
git init | |
git add README.md | |
git commit -m "first commit" | |
git branch -M main | |
git remote add origin https://github.com/josanua/booilerplate-for-custom-WP-plugin.git | |
git push -u origin main | |
//--> issue with password, issue with ssh conection, Authentication failed, ssh Error | |
https://docs.github.com/en/get-started/getting-started-with-git/managing-remote-repositories | |
You can use the command git remote set-url to change a remote's URL. | |
// Replace username with your GitHub username and repo with your repository name. | |
git remote set-url origin [email protected]:username/repo.git | |
// -- work Branches -- // | |
// https://githowto.com/what_is_origin | |
// https://githowto.com/remote_branches | |
// https://www.nobledesktop.com/learn/git/git-branches | |
// https://devconnected.com/how-to-push-git-branch-to-remote/ | |
// https://www.nobledesktop.com/learn/git/git-branches | |
// To get more information about 'origin' branch | |
git remote show origin | |
// To see local branches, run this command: | |
git branch | |
// print the current branch’s name. | |
git branch --show-current | |
// To see remote branches, run this command: | |
git branch -r | |
// To see all local and remote branches, run this command: | |
git branch -a | |
// create new branch and switch to them | |
git branch branchName | |
git checkout branchName | |
git branch branchName/branchDescription (create new branch) | |
git checkout develop (only switch to develop) | |
// short version, the same, short create new branch and switch | |
git checkout -b my-feature | |
// necessary to do after branch ceating, for pushing on git server | |
git push --set-upstream origin my-feature | |
// To configure the initial branch name to use in all of your new repositories, | |
// which will suppress this warning, call: | |
git config --global init.defaultBranch <name> | |
// The just-created branch can be renamed via this command: | |
git branch -m <name> | |
git checkout -b branchName (create and switch to new branch) | |
// push on git created branch | |
git push --set-upstream origin <branch name> | |
// or | |
git push -u origin <branch name> | |
// update la un branch de pe altul, update la branch | |
git pull origin branch-name (in branch-ul in care esti la moment) | |
git checkout - (quick change in the last worked branch) | |
// delete branch locally | |
https://www.freecodecamp.org/news/how-to-delete-a-git-branch-both-locally-and-remotely/ | |
git branch -d localBranchName | |
// delete branch remotely | |
git push origin --delete remoteBranchName | |
// merge branches, connect branches | |
git merge branchName (to branch what is need) | |
// --- first upload from local on created repo | |
// https://www.youtube.com/watch?v=JvW3FGPdtVU | |
1. create repo without README file | |
2. like a normally to this task | |
git init | |
git remote add origin "Address from git" | |
git add . | |
git commit -m | |
git push origin main (git push -u origin main) | |
// -- Git Flow, work flow -- // | |
git checkout -b feature/description-text (if do some new feature/changes) | |
git checkout -b bug/description-text (for bug fixes) | |
git checkout -b release/1.0 (for release) | |
// flow terms | |
master - produsul final, versiune pentru client | |
hotfix | |
release - premaster, nu se face functional nou pe ea | |
develop - functional nou care mereu lucreaza, versiune pentru echipa | |
feature - functional in elaborare | |
// intoarce inapoi de la ultimul commit | |
git restore filename | |
// update la un branch de pe altul, update la branch | |
git pull origin branch-name (in branch-ul in care esti la moment) | |
// -- Commits/push -- // | |
https://github.com/git-guides/git-add | |
git add . (all files) | |
git commit -m "text message" | |
git commit -am "message" (execute git add . and commit commands) | |
git push | |
// -- Procesul nostru de lucru -- // | |
1. Fac upload la develop branch ( Fac pull request ) | |
2. Apoi fac branch-ul meu care este necesar ( git checkout -b feature/task_name_id ) | |
3. Fac modificarile ( sau fac intii modificarile apoi branch-ul ) | |
4. Fac commit push | |
// -- Git in IDE -- // | |
Command + K - Commit | |
// -- git history log, git commit list -- // | |
https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History | |
git log | |
git log --since=2.weeks (2 years 1 day 3 minutes ago) | |
git log --pretty=oneline (cool view) | |
git log --pretty=format:"%h - %an, %ar : %s" | |
// change commit messages | |
https://linuxize.com/post/change-git-commit-message/ | |
// Change latest unpushed commit | |
git commit --amend -m "New commit message." | |
// Remove Unpushed Commits in Git | |
https://www.delftstack.com/howto/git/git-remove-unpushed-commit/#:~:text=Use%20the%20git%20reset%20Command,in%20the%20local%20Git%20repository. | |
git reset --soft HEAD~1 | |
git reset --hard HEAD~1 | |
// Change latest pushed commit, edit last commit, change last commit | |
1. git commit --amend -m "New commit message." | |
2. git push --force <remoteName> <branchName> | |
// edit last commit, update commit message | |
git commit --amend -m "an updated commit message" | |
// -- Top 10 Git Commands that all you need to know -- // | |
https://scriptjunction.com/devops/github/top-10-git-commands/ | |
1: When you switch to a new branch locally from master branch and this branch does not exist on github yet | |
git checkout -b feature-branch (Switched to a new branch 'feature-branch') | |
git push --set-upstream origin feature-branch (will set the upstream and create a new branch with your changes) | |
2: When you have some un-committed changes on local repo but you want to get latest changes from remote branch | |
// setup Git ignore file | |
https://git-scm.com/docs/gitignore | |
https://www.pluralsight.com/guides/how-to-use-gitignore-file | |
# If you want to ignore a file that is already checked in, you must untrack the file before you add a rule to ignore it. From your terminal, untrack the file. | |
# remove from cache | |
$ git rm --cached FILENAME | |
$ git rm -r --cached FILENAME | |
// another example | |
https://www.atlassian.com/git/tutorials/saving-changes/gitignore | |
$ echo debug.log >> .gitignore | |
$ git rm --cached debug.log | |
rm 'debug.log' (will remove file from folder) | |
$ git commit -m "Start ignoring debug.log" | |
// from ChatGPT working | |
git rm --cached <file> | |
git commit -m "Remove <file> from repository" | |
git push origin <branch-name> | |
// *** Errors *** // | |
-> Please commit your changes or stash them before you merge. | |
https://stackoverflow.com/questions/1125968/how-do-i-force-git-pull-to-overwrite-local-files | |
-> Hard reset, reset to original, delete changes, remove unpushed commits, remove commits | |
// If you dont care about your local changes, try to reset it to HEAD (original state), e.g. | |
//This will remove all uncommitted changes, even if staged, | |
$ git reset --hard | |
$ git reset --hard HEAD | |
-> non-fast-forward error | |
https://docs.github.com/en/get-started/using-git/dealing-with-non-fast-forward-errors | |
// quick fix | |
git pull origin YOUR_BRANCH_NAME | |
// -- git ignore issues, uncheck tracked file, Cleaning Ignored Files, git ignore files -- // | |
https://www.atlassian.com/git/tutorials/saving-changes/gitignore#ignoring-a-previously-committed | |
https://www.git-tower.com/learn/git/faq/ignore-tracked-files-in-git | |
https://www.youtube.com/watch?v=0DiNdpUx5_Q | |
https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files#configuring-ignored-files-for-all-repositories-on-your-computer | |
1. you'll need to delete the file from your repository and then add a .gitignore rule for it. | |
2. Use this commands | |
# Remove the files from the index (not the actual files in the working copy) | |
$ git rm -r --cached . | |
# Add these removals to the Staging Area... | |
$ git add . | |
# ...and commit them! | |
$ git commit -m "Clean up ignored files" | |
// use this | |
git rm --cached file/foldername | |
// rebase, branch divergent branch divergents, push conflict, | |
https://poanchen.github.io/blog/2020/09/19/what-to-do-when-git-branch-has-diverged | |
git rebase origin/master | |
git merge origin/master | |
// if standard function don't helped | |
// if -> fatal: Not possible to fast-forward, aborting”. | |
git pull origin --rebase | |
// https://www.atlassian.com/git/tutorials/using-branches/git-merge | |
// https://git-scm.com/docs/git-merge | |
git merge : - Join two or more development histories together | |
// work history, git history | |
https://www.warp.dev/terminus/git-commit-history#:~:text=To%20list%20commits%20as%20a,history%20of%20the%20entire%20repository. | |
// Show the last git commits | |
git show HEAD | |
// Viewing a git branch’s entire history | |
git log : shows the commit history for the branch currently checked out. If you have not checked out a branch, this will show you the commit history of the entire repository. | |
git log <branch-name> | |
// migrate git provider | |
https://cloud.google.com/looker/docs/best-practices/how-to-migrate-to-a-new-git-repo | |
// This shows you the remote(s) | |
git remote -v | |
// Next, set the origin remote to the new repo | |
git remote set-url origin [email protected]:your_organization/PROJECT_NAME.git | |
git push origin master | |
// issue with Password authentication | |
//--> If you already have SSH set up and want to update the remote URL of your current repository to use SSH, follow these steps: | |
https://docs.github.com/en/get-started/getting-started-with-git/managing-remote-repositories | |
You can use the command git remote set-url to change a remote's URL. | |
// 1. Replace username with your GitHub username and repo with your repository name. | |
git remote set-url origin [email protected]:username/repo.git | |
// 2. Verify the change | |
git remote -v | |
// 3. Push your changes | |
git push origin master (branch name) | |
// -- Reset -- // | |
git reset [--soft | --mixed | --hard] [commit] | |
// -- git submodules -- // | |
https://www.youtube.com/watch?v=gSlXo2iLBro | |
// After repo pull must do command | |
'git submodule update --init' | |
// or then you start to pull the project | |
git pull --recurse-submodules | |
// or change in git settings | |
git config submodule.recurse true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment