Skip to content

Instantly share code, notes, and snippets.

@AlbertoVargasMoreno
Last active October 5, 2023 17:44
Show Gist options
  • Save AlbertoVargasMoreno/2c67cbf026eed89929e1103b6ca969fa to your computer and use it in GitHub Desktop.
Save AlbertoVargasMoreno/2c67cbf026eed89929e1103b6ca969fa to your computer and use it in GitHub Desktop.

GIT

Gitignore

ignore * except

https://stackoverflow.com/questions/987142/make-gitignore-ignore-everything-except-a-few-files


Undoing

git reset --soft HEAD~; git reset

revert last commit

git revert HEAD

https://stackoverflow.com/questions/1463340/how-can-i-revert-multiple-git-commits

https://www.git-tower.com/learn/git/commands/git-revert/

undo commit, keep changes

git reset HEAD~1 --soft

https://stackoverflow.com/questions/19859486/how-to-un-commit-last-un-pushed-git-commit-without-losing-the-changes

delete a commit, Delete the most recent commit, destroying the work you've done:

git reset --hard HEAD~1

https://stackoverflow.com/questions/3197413/how-do-i-delete-unpushed-git-commits

git reflog

https://robertbasic.com/blog/use-git-reflog-to-split-two-squashed-commits/


Stashing

How to Name a Stash

git stash push -m [message]

https://phoenixnap.com/kb/git-stash-name

Pop specific stash

git stash apply stash@{2}

https://melvingeorge.me/blog/pop-specific-stash-git

Remove a stash

git show stash@{0}

git stash drop stash@{0}

https://www.designcise.com/web/tutorial/how-to-remove-git-stash-entries

Stash one file

git stash push -m 'My message' -- path/to/file.txt

https://timmousk.com/blog/git-stash-one-file/

apply stash specific file

git checkout stash@{0} -- <filename>

https://stackoverflow.com/questions/15212882/how-can-i-apply-only-some-of-a-git-stash


Editing my local commits

Preventing dumb conflicts

https://stackoverflow.com/questions/6836461/updating-the-current-branch-from-parent-branch

https://duckduckgo.com/?t=ffab&q=to+keep+track+of+parent+branch+changes+what+is+better+rabse+or+merge+&ia=web

https://www.theserverside.com/video/How-to-easily-merge-and-resolve-git-stash-pop-conflicts

Conflicts

https://timwise.co.uk/2019/10/14/merge-vs-rebase/

https://belev.dev/git-merge-vs-rebase-to-keep-feature-branch-up-to-date

how to rebase

https://opensource.com/article/20/4/git-rebase-i

git rebase -i HEAD~3

https://www.golinuxcloud.com/git-squash-commits/

don't rebase whole branch, rebase specific commit git

https://stackoverflow.com/questions/7744049/git-how-to-rebase-to-a-specific-commit

git rebase bb5685aa

git checkout <branch_that_will_rebase>
git rebase <commitB>

alternative

git branch temp <commit>
git checkout <branch>
git rebase temp
git branch -d temp

split commits

git reset HEAD~

https://stackoverflow.com/questions/6217156/break-a-previous-commit-into-multiple-commits

  $ git rebase -i HEAD~3
  # choose edit 
  $ git reset HEAD~
  $ git rebase --continue

split squashed commits

https://robertbasic.com/blog/use-git-reflog-to-split-two-squashed-commits/

merge and remove branch

git merge source-branch && git branch -d source-branch

https://stackoverflow.com/questions/35507239/merge-and-delete-branch-in-one-step-command

Branching

How many commits am I behind from

https://stackoverflow.com/questions/27407343/how-to-see-how-many-commits-a-local-branch-is-ahead-behind-another-local-branch

See changes in a branch

git checkout <notMainDev>

git diff --name-only <mainDev>

bringing changes to my branch

https://stackoverflow.com/questions/37709298/how-to-get-changes-from-another-branch

git log graph two branches

http://stackoverflow.com/questions/26784396/ddg#26784584

create branch from commit

https://stackoverflow.com/questions/8483983/how-to-create-the-branch-from-specific-commit-in-different-branch

git branch test 07aeec983bfc17c25f0b0a7c1d47da8e35df7af8

git branch tmp 1a32846b

git cherry-pick

git cherry-pick f

https://www.atlassian.com/es/git/tutorials/cherry-pick

stop using cherry-pick

https://devblogs.microsoft.com/oldnewthing/20180312-00/?p=98215

go to an old commit, detached HEAD

https://stackoverflow.com/questions/42082338/git-checkout-switching-back-to-head

https://stackoverflow.com/questions/50461380/how-to-checkout-on-an-old-commit-and-push-it-on-current-branch


Remote

log of remote

git log origin/muestra-medica-report --oneline

https://stackoverflow.com/a/38987152

http://stackoverflow.com/questions/16315379/ddg#16315536

git fetch
git log FETCH_HEAD

check changes from Remote before merging

https://stackoverflow.com/questions/2514270/how-to-check-for-changes-on-remote-origin-git-repository

git fetch origin
# diff shows what will be applied if I accept the remote changes.
git diff HEAD origin/master
git pull origin

change remote origin

https://devconnected.com/how-to-change-git-remote-origin/

# git remote set-url <remote_name> <remote_url>
git remote set-url origin https://git-repo/new-repository.git

push local existing repository from the command line

git remote add origin https://github.com/AlbertoVargasMoreno/tdd_phpunit.git
git branch -M main
git push -u origin main

unlinking from original repo

https://stackoverflow.com/questions/19801455/git-removing-upstream-from-local-repository#21835035

git remote remove origin

Delete remote branch (push nothing)

git push origin --delete branchname

commit message

https://daily-dev-tips.com/posts/git-basics-conventional-commits/

    * `build`: Changes that affect the build system like gulp, npm, etc
    * `ci`: Changes made to the CI configuration like Travis, Circle, Actions
    * `chore`: Other changes that don't modify src or test files
    * `docs`: Documentation only changes
    * `feat`: A new feature
    * `fix`: Fixed a bug
    * `perf`: Code changes that improve performance
    * `refactor`: A code change that's not mainly a bug or new feature
    * `revert`: Revert a previous commit
    * `style`: Changes to styling like white space, formatting, semi-colons)
    * `test`: Add or fix tests

https://stackoverflow.com/questions/64290635/how-to-classify-ui-change-according-to-the-conventional-commits-specification

Terminal Tools

find and replace in vim

https://linuxize.com/post/vim-find-replace/

https://stackoverflow.com/questions/46781951/efficient-way-to-delete-line-containing-certain-text-in-vim-with-prompt#46807561

find files unix

find . -name names.txt

compare files unix

https://www.unixtutorial.org/how-to-compare-directories-in-unix/

https://stackoverflow.com/questions/2019857/diff-files-present-in-two-different-directories

https://stackoverflow.com/questions/4715885/compare-two-files-in-unix

search with grep

git reflog | grep 'merge'

https://stackoverflow.com/questions/58080856/how-does-one-use-regex-in-grep-in-git-reflog

my ip

$ curl ipinfo.io/ip

177.245.148.4

Learn about GIT

https://gist.github.com/hofmannsven/6814451

https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/How-to-use-the-git-log-graph-command

branching model, workflow

https://www.dmitriydubson.com/post/trunk-dev-wip-commits/

A successful Git branching model: https://nvie.com/posts/a-successful-git-branching-model/

commit instead of stashing

https://stackoverflow.com/a/2187113

https://stackoverflow.com/questions/42358448/how-to-backup-git-stash-content

good workflow?

https://stackoverflow.com/questions/58857916/git-a-better-way-for-leaving-wip-branch-and-start-working-on-a-another-branch

good practices in git?

git reset --soft HEAD~; git reset

https://stackoverflow.com/questions/2187000/untracked-files-between-branches-in-git

small commits: good practices

https://www.technicalfeeder.com/2022/01/git-big-commit-vs-small-commit/

https://betterprogramming.pub/why-you-should-write-small-git-commits-c9a042737aa6

Git

1. Crear el repositorio remoto en el servidor de la oficina:
	1.1 mkdir directorio_de_proyecto
	1.2 cd directorio_de_proyecto
	1.3 git init --bare

2. En la carpeta del proyecto local añadir la dirección del repositorio remoto (deberá activar la VPN)
	2.1 git config --list // Permite ver la configuración global de git
	2.2 git remote set-url origin daniela@192.168.XXX.XXX:/home/daniela/directorio_de_proyecto/
	2.3 git remote -v //Lista las direcciones remotas asociadas al repo
	2.5 git pull origin master //Traer cambio
	2.4 git push origin master // Enviar cambios
	2.6 git log //revisar cambios
	
	git pull origin master
	git push -u origin <branch>
git diff HEAD^ HEAD -- midbucket.view.inc

bring remote branch to local

git checkout -b <branch_name> /<branch_name>

https://stackoverflow.com/questions/22620393/various-ways-to-remove-local-git-changes

compare two commits one file git

git diff master f4l4f3l -- src/toaster.c

https://stackoverflow.com/questions/5550137/using-git-to-compare-one-file-from-two-commits

Tagging

https://stackoverflow.com/questions/1307114/how-can-i-archive-git-branches

git tag [-a -m "some description maybe"] archive/<any_name_you_like> <branchname or commit>

https://stackoverflow.com/questions/19542301/delete-all-tags-from-a-git-repository

git tag -d tagname

create tags

https://stackoverflow.com/questions/4404172/how-to-tag-an-older-commit-in-git

https://stackoverflow.com/questions/32597209/python-not-working-in-the-command-line-of-git-bash

download with curl

curl -O <url>

https://stackoverflow.com/questions/7751555/how-to-resolve-git-stash-conflict-without-commit

name releases

https://stackoverflow.com/questions/410126/whats-your-prefered-method-to-name-your-software-releases

dont open editor when rebase

https://stackoverflow.com/questions/43489971/how-to-suppress-the-editor-for-git-rebase-continue

which files were modified between commits

https://coderwall.com/p/lz0uva/find-all-files-modified-between-commits-in-git git diff --name-status HEAD HEAD~3

log only commits that changed specific file

https://stackoverflow.com/questions/3701404/how-to-list-all-commits-that-changed-a-specific-file git log --follow -- filename

how to classify commit

https://stackoverflow.com/questions/61262376/questions-about-conventional-commit-messages-in-git

Remove information on branches that were deleted on origin

git fetch --prune

change date

git commit --amend --date="$(date)"

which remote is connected is to my local branch

https://stackoverflow.com/questions/171550/find-out-which-remote-branch-a-local-branch-is-tracking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment