-
Notifications
You must be signed in to change notification settings - Fork 0
ferng edited this page Oct 16, 2025
·
44 revisions
Thank goodness Linus came up with Git, cvs, was alright, SVN was definitely top heavy, merging branches, eurgh. Now, don't get me wrong you can cock up with Git, but it's also very easy to fix it when you do.
git config --global alias.lg "log --color --graph --pretty=format:'%C(yellow)%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
#common
git config --global user.name "ferng001"
git config --global user.email some_email@gmail.com
git config --global core.autocrlf input
git config --global core.filemode false
git config --global credential.helper cache
git config --global push.default simple
git config --global core.editor "vim"
git config --global diff.tool vimdiff
git config --global difftool.prompt false
git config --global alias.d difftool
git config --global merge.tool vimdiff
git config --global mergetool.prompt false
git config --global merge.conflictstyle diff3
git config --global alias.m mergetool
#remove config
git config --global --unset diff.tool vimdiff
#repo only user
git config user.name "Fern Gonzalez"
git config user.email fg@pep.security
#set up proxy
export http_proxy=fernandog:myPassword@10.1.10.15:8080
export https_proxy=fernandog:myPassword@10.1.10.15:8080cd ~/
mkdir .ssh
ls -al .ssh
ssh-keygen -t rsa -C "some_email@gmail.com" -f ~/.ssh/id_home_rsa
#check ssh-agent is running
eval "$(ssh-agent -s)"
#add ssh key to agent
ssh-add ~/.ssh/id_home_rsa
#repeat for work
#vi ~/.ssh/config
Host home
Hostname github.com
IdentityFile ~/.ssh/id_home_rsa
User ferng
Host work
Hostname work.example.com
IdentityFile ~/.ssh/id_work_rsa
User <your work acct>
#file permissions
chown -R fern:fern ~/.ssh/
chmod 600 ~/.ssh/config
chmod 600 .ssh/id_home_rsa*
chmod 600 .ssh/id_work_rsa*- configuration and key generation - windows
- use puttygen to pull out public key (prom privatekeys)
| Parameter | Value |
|---|---|
| Session Name | zzzproxy |
| Host Name | bitbucket.org |
| Port | 22 |
| Putty Proxy Configuration | |
|---|---|
| Type | HTTP |
| Host | hjs1-proxy-01 |
| Port | 3128 |
| Proxy command | connect %host %port\n |
# at home directory
vi .profile
GIT_SSH=/cygdrive/c/Program\ Files\ \(x86\)/PuTTY/plink.exe
export GIT_SSHgit clone git@zzzproxy:ferng001/monipoop.gitgit log --show all history
git fetch origin
git merge origin/master#review what's changed etc
git status -u
#tidy stuff if necessary and when your're happy this will add / update / delete files as necessary
gitCom.sh "this is my comment"
#review project history
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
#or if alias has been setup
git lg
#and to list the changes
git lg -p#list branches
git branch
#throw away local changes
git checkout -f
#merge remote changes into my local copy
git pull origin <branch>
#delete remote branch
git push origin :feature/test
git push origin --delete core-project
#delete local branch
git branch -D branch
#update my branch with changes from dev keeping my commit at the top
git rebase <dev> <mine>
#list all branches with creation date
git for-each-ref --format="%(refname:short) %(creatordate)" refs/heads/
#delete old local branchs
git remote prune origin
git branch -vv|grep gone
# review output then
git branch -vv|grep gone | cut -d " " -f3|xargs -r git branch -D#delete tags
git tag -d v1.1.0-RC2
git push --delete origin v1.1.0-RC2
#add tags
git tag -a v1.1.0-RC2 -m "v1.1.0-RC2"
git push --tags
git tag -a v1.1.0-RC2 -m "v1.0.1-RC2" acaf399637b29b754da0724d86#amend commit without changing message
git commit --amend --no-edit
#differences between current and last commit
git diff
#differences between current and last commit excluding one file
git diff -- . ':(exclude)package-lock.json'
#differences between last commit and repository
git diff origin/master
#reset working tree to the last commit / clean up any left over files
git reset --hard HEAD
#what is going to be cleaned up
git clean -n
#clean it up
git clean -f -d
#reset working head to remote
git fetch origin
git reset --hard origin/master
#undo any number of previous commits
git reset --hard 35d1df5207d
git reset --soft ORIG_HEAD
git commit
#squash last few commits
git reset --soft HEAD~3 && git commit
#update date
git commit --amend --date="2005-04-07T22:13:13+03:00"
git commit --amend --no-edit --date=now
export GIT_COMMITTER_DATE='2023-11-02T17:20:13+03:00'
git commit --amend --no-edit --date='2023-11-02T17:20:13+03:00'
unset GIT_COMMITTER_DATE
git log --pretty=fuller
#cherry-pick
git cherry-pick A^..B # A to B inclusive
git cherry-pick A..B # A to B excluding A- Fork project into my repo
- Create branch for change
git fetch origin
git checkout -b new_branch origin/new_branch- Make changes
git pull --rebase main master # update with other changes from their repo
git rebase --continue # if you need to fix any conflicts
git merge master
git checkout master
git merge --no-ff new_branch
git push origin master- Create pull request comparing my branch with their branch
# start bisect
git bisect start
#mark latest commit as bad
git bisect bad
#mark a commit as bad
git bisect bad f7e0de91f
# mark the commit where it last worked
git bisect good 0a2d47e45
# git bisects the commits (using a big binary chop) then you run the tests
# if the bug doesn't exist in this chunk
git bisect good
#if it does
git bisect bad
# git then loops until there is no more chopping to do. now you know what commit broke it so stop bisecting
git bisect reset#make a new project
mkdir new_proj
cd new_proj
git init
vi README.md
git add .
git commit -m “Initial commit”
#merge a project into it
git remote add -f cart git@github.com:ferng/cart.git
git merge cart/main --allow-unrelated-histories
#fix any conflicts, move files about
#remove unwanted remote
git remote rm calendar
#final post merge push