Git shell: Windows: https://gitforwindows.org/ MinGW BASH shell Joe: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" brew install joe brew link --overwrite joe # Initial config git config --global user.name "Christian Wolff" git config --global user.email "c@scara.com" git config --global --edit git config credential.helper store git config --global http.sslVerify false # Create new repository #mkdir my-repo #cd my-repo #git init . git init my-repo # Connect new repo to GitLab git remote add origin git@git.scara.com:my-repo.git # Create local dev branch git checkout dev_integration git pull git checkout -b YYYYMMDD_cwolff_Project # See what's up with local branch git status git diff git diff --cached # Create a patch of local changes git diff > ../YYYYMMDD_cwolff_xyz.patch # Prepare files for commit git add # Revert 'add' git reset # Prepare all updated files that are already part of the repository git add -u # View staged changes git diff --cached # Commit changes to local dev branch git commit git commit --amend --reset-author # Upload local dev branch git push # Create dev branch on server, then upload git push --set-upstream origin YYYYMMDD_cwolff_Project # See commited changes git log git log | head # Diff between two commits git diff 6f9a56764bc3fe59a650d82fb42c8580971d0183 16f45c059719eafc59ddca4e6f9452c775cecb09 # Submodules # Create submodule by cloning into current repository git submodule add https://... git commit (changes should be .gitmodules and new repo dir) # Recursive clone of submodules along with main repo git clone --recursive https://... git clone --recurse-submodules https://... # Recursive clone of submodules in already cloned repo git submodule sync git submodule update --init --recursive # Update submodules git submodule update git submodule update --recursive --remote git submodule foreach "(git checkout master; git pull)&" # change source of submodule git submodule set-url [--] # Update local git git pull # Merge changes from master into current dev branch git merge origin/master git merge origin/dev_integration git rebase master git rebase dev_integration git rebase --continue # Switch to master git checkout master # List local dev branches git branch # Switch to dev branch git checkout YYYYMMDD_cwolff_Project # Merge in one single commit git merge --squash YYYYMMDD_cwolff_Project # Cherry-pick single commits from other branches, as new commit git cherry-pick 83513aa6ca30051a9be5d79548d1c71eb3aac718 # Add another repo, to cherry-pick commits from there git remote add other https://example.link/repository.git git fetch other # Discard changes in a file git restore git checkout -- # Discard all local changes git reset --hard origin/master git reset --hard origin/dev_integration # Discard most recent commit (?) git reset HEAD^ # remove commit locally git push origin +HEAD # force-push the new HEAD commit # Clean up (remove) untracked files and dirs git clean -f -d # Where am I? git remote show origin # Revert files to previous version, at hash c5f567 git checkout c5f567 -- file1/to/restore file2/to/restore # Revert files to previous version, before hash c5f567 git checkout c5f567~1 -- file1/to/restore file2/to/restore # Mirror repository # Mirror a repository in another location, including getting updates from # the original, you can clone a mirror and periodically push the changes. # Create a bare mirrored clone of the repository. git clone --mirror https://github.com/exampleuser/repository-to-mirror.git # Set the push location to your mirror. cd repository-to-mirror.git git remote set-url --push origin https://github.com/exampleuser/mirrored # As with a bare clone, a mirrored clone includes all remote branches and tags, # but all local references will be overwritten each time you fetch, so it # will always be the same as the original repository. Setting the URL for # pushes simplifies pushing to your mirror. To update your mirror, # fetch updates and push. git fetch -p origin git push --mirror