Title: git notes Subject: As I learn git, these are issues and fixes # Don't be a Git Twit # REF: https://kernowsoul.com/blog/2012/06/20/4-ways-to-avoid-merge-commits-in-git/ # To visualize git command cycle # REF: https://medium.com/@dilankam/most-frequently-used-git-commands-3f24cd4b484a add--> commit--> push--> Working Staging Local Remote <--reset <--reset <--fetch|pull <------------------reset-hard #----------------------------------------------------------- # Create NEW share repo (others can push to) # BARE REPOSITORY IS NEEDED IF IT WILL RECEIVE PUSH # push updates the remote's branch+HEAD reference, and working-copy and staging-area # a bare repo has to working copy or staging area #----------------------------------------------------------- mkdir repo.git pushd repo.git git init --bare --shared=group #----------------------------------------------------------- # Convert EXISTING repo to BARE #----------------------------------------------------------- pushd repo.git git config --bool core.bare true git config receive.denyCurrentBranch ignore git config core.sharedRepository group chgrp -R foo repodir chmod -R g+w repodir #----------------------------------------------------------- # Some User stuff #----------------------------------------------------------- # Check your config git config -l # Create Aliases git config --global alias.ac '!git add -A && git commit' git config --global alias.logg '!git log --graph --oneline --date-order --decorate --color --all' # Set Identity git config --global user.email 'john@stilen.com' git config --global user.name 'John Stile' git config --global user.email 'john@stilen.com' # merge.tool: Run this to see suggestions: git mergetool git config --global merge.tool=meld # default pull --rebase from master git config branch.master.rebase true # default pull to --ff-only to avoid accidental Merge git config --global pull.ff only #----------------------------------------------------------- # Handy things to get to know #----------------------------------------------------------- # show commits in remote but not in local branch git log --branches --not --remotes=origin # show commits on All remote branches git log --remotes=origin #------------------------------------------------------------------------------------------------ # update a forked in github repo #------------------------------------------------------------------------------------------------ In github: https://github.com/MeyerSoundLaboratoriesInc/VTK is forked from: https://gitlab.kitware.com/vtk/vtk My fork needs their updated master branch and tags. # 1. Clone thier repo git clone git@github.com:Kitware/VTK.git github_VTK # 2. Get in position cd github_VTK # 3. Fetch their tags git fetch --tags # 4. Checkout the master branch git checkout master # 5. Add my fork as a new remote git remote add myfork git@github.com:MeyerSoundLaboratoriesInc/VTK.git # 6. Push master and tags to my fork git push --tags myfork master #NOTE: Not sure why this isn't a button in github web interface. #------------------------------------------------------------ # This is a workflow using rebase, to keep a linear history #------------------------------------------------------------ In this flow: 1. master is a 'stable' branch, 2. my_feature is a single developer dev branches 3. At the end, my_feature is merged into master and removed. 1) before starting feature branch, update master git checkout master git pull --ff-only origin master 2) make your feature branch git checkout -b my_feature 3) make changes in the my_feature branch git commit one_fish -m 'doing my work1' git commit two_fish -m 'doing my work2' git commit red_fish -m 'doing my work3' git commit blue_fish -m 'doing my work4' 4) Initally one can just push to remote feature branch git push origin my_feature 5) Frequently take updates from master, resolve conflicts, push remote feature branch git pull origin master --rebase git push -f origin my_feature *NOTE: The -f is needed because history changes in rebase 7) When feature is complete, merge to master: git pull --rebase origin master git push origin refs/heads/my_feature:refs/heads/master 8) Update your local master git checkout master git pull --ff-only 9) Get rid of your local and remote branches git push origin -d my_feature git branch -D my_feature git remote prune origin Problem: I have 3 dev machines sharing a feature branch. Once one machine has rebased from master, and force pushed to origin, how do I update the other dev machines? Solution1: This one seems to work, but some will not agree. With no changes on the other def machine... git pull origin my_feature -s recursive -X theirs Solution2: This was recommended form a friend, but didn't work git pull +refs/heads/my_feature #------------------------------------------------------------------------------------------------ # BEGIN: move repository content with history to another repo and directory layout #------------------------------------------------------------------------------------------------ # Problem: # 1. I wrote an app using one repository, but now it needs to go in another. # e.g. must migrate github repo to gitblit repo # 2. The folder structure of the dev repo is not compatile with the destination repo. # e.g. dev repo has eveyrthing in the root folder, but dest repo needs stuff under tableau_view. # 3. I must preserve history. # e.g. Linearly apply my history above existing. # # Solution below: # 1. Modify the dev repo, move files under a subdirectory, though all of history. # * I don't want a revision that puts my files in the root folder. # 2. Pull my app from the dev repo into the destination repo, preserving commit history. # # Base idea came from here, but I had a hard time making it work. # REF: https://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history/ # #-------------------------------------- # Step 1: relocate files within a repo #-------------------------------------- # # Checkout dev repo # git clone git@github.com:johnstile/tableau_view2.git github_tableau_view2 pushd github_tableau_view2 git checkout master git pull origin master # To merge this repo with another repo, I must flatten out branch merges, # because the destination repository does not have the branches. # Do an Interactive Rebase, to squash and edit commits as needed. # Choose a commit before the commits you want to change. # git rebase -i 42d29650 # # To edit an author 'pick' to 'edit' next to the hash to modify # And do :wq # # Then for each line wiht 'edit', provide the info to change: git commit --amend --author="John Stile " git rebase --continue # # For each conflict, work it out and continue # This was painful, but I compared newer versions of the code area with the conflict to chose who should win. # Then I had to edit the files and rmeove the >>>>> ==== <<<< and offending code. # git rebase --continue # # At this point I removed the origin as I don't want to push these changes to github. # git remote rm origin #---------------------------------------------------------------------------------- # Now it is time to relocate the file thoughout history # from to tableau_view subfolder # # This was totally strange, and I'm not very efficent, but it worked. # You can't change the file if it isn't there, so tests must be made. # You can't move things to a directory if it doesn't exist. # You can't count on much, so doing too much && doesn't work. # The --tree-filter scripts did the job fine for me, but they are hacky. #---------------------------------------------------------------------------------- git filter-branch --tree-filter 'test -f "webpack.config.js" && mkdir tableau_view && mv webpack.config.js tableau_view || echo "Nothing to do"' HEAD git filter-branch -f --tree-filter 'test -d tableau_auth && $(mkdir tableau_view ; mv tableau_auth tableau_view) || echo "Nothing to do"' HEAD git filter-branch -f --tree-filter 'test -d src && $(mkdir tableau_view ; mv src tableau_view) || echo "Nothing to do"' HEAD git filter-branch -f --tree-filter 'test -f package.json && $(mkdir tableau_view ; mv package.json tableau_view) || echo "Nothing to do"' HEAD git filter-branch -f --tree-filter 'test -f package-lock.json && $(mkdir tableau_view ; mv package-lock.json tableau_view) || echo "Nothing to do"' HEAD git filter-branch -f --tree-filter 'test -f setup.bash && $(mkdir tableau_view ; mv setup.bash tableau_view) || echo "Nothing to do"' HEAD git filter-branch -f --tree-filter 'test -f .eslintrc.json && $(mkdir tableau_view ; mv .eslintrc.json tableau_view) || echo "Nothing to do"' HEAD git filter-branch -f --tree-filter 'test -f .gitignore && $(mkdir tableau_view ; mv .gitignore tableau_view) || echo "Nothing to do"' HEAD # # NOTE: Simply moving the file in a commit does not change the past locaiton. # These files can't be allowed to exist in the root if the repo at any commit. # # !! Don't do this # !! mkdir tableau_view # !! git mv webpack.config.js tableau_auth src setup.bash package-lock.json package.json .eslintrc.json .gitignore tableau_view # !! git commit . -m 'Relocate tableau view app under directory tableau_view' #-------------------------------------- # Step 2: merge dev repo into dest repo. #-------------------------------------- git clone --recursive ssh://john@gitblit.mydomain.com:29418/g2/engineering.git gitblit_engineering_merge_test cd gitblit_engineering_merge_test # # Create a branch to play in # git checkout -b tableau_view # # Add path to the dev repo clone with mutilated hisotry and structure # git remote add origin-tmp-repo /home/jstile/github_tableau_view2 # # Poison our repo with the heathen files and false history # git pull origin-tmp-repo master --allow-unrelated-histories # # gitk looks good! But we need a rebase # gitk # # Lets get linear, linear. # git pull --rebase origin master # # gitk lookn real good! History is now liner # gitk # # SANITY CHECK: Compare what is currently running against this get repo. # Some things are missing: node stuff, python virtual env and logs # Everyhing looks great. # git meld tableau_view /var/www/tableau_view # # Merge to origin master # git push origin refs/heads/tableau_view:refs/heads/master git pull origin master # # Cleanup Destination Repo # Remove the folders just to keep you honest and prevent possible usage. # Get a new clone. # #------------------------------------------------------------------------------------------------ # END: modify history, move files for all history, and move files to another repo with history. #------------------------------------------------------------------------------------------------ #========================================= A git push does 2 things. 1) there is a text file called the "ref". Each tag and branch is basically a "ref" and that text file contains a commit ID. When you push to a "branch", you're actually pushing to a "ref" and that text file gets updated with the commit ID of the HEAD of whatever your pushing to the ref If I say "git push origin master" and I'm on "my_changes" branch and the HEAD is abc123, then the push will update "refs/heads/master" to be "abc123" I can spool up a bunch of commits, and when i push it sends the ref changes up up one at a time. You can cat .git/refs/heads/master to see where it is. 2) Look at the ref ID, and compare the pre-push commit ID with the ID you are pushing. If they don't match, then the push will upload all of the commit objects that would make a chain from the one to the other. If that chain can't be made, then the push is blocked (unless you do --force) So, let's say the server's refs/heads/master is "abc123", I'm pushing "ghi789", and the chain is like "ghi789" -> "def456" -> "abc123", then it will upload both "ghi789" and "def456" commit objects. #========================================= How to rebase commits from another repository with a different history? https://stackoverflow.com/questions/37673813/how-to-rebase-commits-from-another-repository-with-a-different-history git glone repo # Clone Repo to recieve stuff from another repo git clone git@github.com:foo/repo1.git # change to clone cd repo1 # Add Repo that has commits to be merged git remote add repo2 C:\Path\To\Repo2 # fetch other repo's branches git fetch repo2 git checkout master # list their commits git log repo2/master # Pull in the changes git cherry-pick abc123 #========================================= git status shows change, but git diff does not git format-patch HEAD^ Look at patch git config core.filemode false To ignore permission changes #========================================= ssl cert issues: $ git clone https://myuser@mygit.com/git_repos/mygit.git Cloning into 'g2daemons'... fatal: unable to access 'https://myuser@mygit.com/git_repos/mygit.git': SSL certificate problem: unable to get local issuer certificate Must disable ssl check for self signed certs. git -c http.sslVerify=false clone https://myuser@mygit.com/git_repos/mygit.git #========================================= make a new gitblit repo. cd to exiting code dir touch README.md git init git add README.md git commit -m "first commit" git remote add origin ssh://@my.gitblit.mycomain.com:29418/.git git push -u origin master #========================================= Git a human readable version-revision already I like subversions incrementing rev number that humans can understand, git doesn't do this explictly. Instead there are organic solutions and like every backwater pond, every one is different, but they all stink. http://programmers.stackexchange.com/questions/141973/how-do-you-achieve-a-numeric-versioning-scheme-with-git so tags answers: "which release was this commit based on?" does not answer: "which release will this commit be in?" git describe --long --tags --dirty --always v2.5-release Generated version numbers like this: x.y..r ONE SOLUTION: # OSX and Linux REV="$(git rev-list --count HEAD)" BRANCH="$(git rev-parse --symbolic-full-name --abbrev-ref @{u})" echo "#define MY_VERSION ${BRANCH}-${REV}" > repository_version.h # Windows for /f "delims=" %%a in ('git rev-list --count HEAD') do @set Rev=%%a for /f "delims=" %%a in ('git rev-parse --symbolic-full-name --abbrev-ref @{u}') do @set Branch=%%a @echo #define MY_VERSION %BRANCH%-%REV% >> repository_version.h TWO SOLUTION: git pull --tags git describe r100 git symbolic-ref --short HEAD master echo `git symbolic-ref --short HEAD`-`git describe` master-r100 #========================================= Self signed certs getting you down? env GIT_SSL_NO_VERIFY=true git command git config http.sslVerify "false" #========================================= ssh getting you down? swtich to using https for checkout. #========================================= I have a project that uses code from github projects. We want to make a mirror of it to our internal repo so we can control upstream changes or hackers First create an internal empty repo of the same name in gitblit Second, create mirror from external repo to internal repo git clone --mirror https://github.com/boundarydevices/imx_usb_loader.git cd imx_usb_loader.git git push --mirror ssh://mygit.mydomain.com:29418/imx_usb_loader.git cd .. rm -rf imx_usb_loader.git git clone --mirror https://github.com/ixonos/utp_com.git cd utp_com.git git push --mirror ssh://mygit.mydomain.com:29418/utp_com.git cd .. rm -rf utp_com.git Third, add submodule to my project git clone ssh://mygit.mydomain.com:29418/myproject.git myproject cd myproject mkdir submodules git add submodules git submodule add ssh://mygit.mydomain.com:29418/imx_usb_loader.git imx_usb_loader git submodule add ssh://mygit.mydomain.com:29418/utp_com.git utp_com git commit . -m 'adding submodules for imx_usb_loader and utp_com' git push #========================================= git help glossery #========================================= Connecting to git as different user than the shell My shell user is foo, gitblit user is bar. To checkout from gitblit the url must contain 'bar@' But with submodules, the .gitmodules url cant contain this, as many other people use it. I think the best solution is to use ~/.ssh/config setting a rule for the git host cat >> ~/.ssh/config <<'EOF' Host git.my.domain.com User bar EOF git submodule update --recursive Now it all works. #========================================= solve timeout cloning due to slow network or bad server configs ~/.ssh/config Host * ForwardX11 no ServerAliveInterval 86400 ServerAliveCountMax 4 Host git.hostA.com User johns Host git.hostB.com User johns Host github.com User fubar_user #========================================= Migration from svn to git In svn everything is a branch (even tags) In git branches and tags are different. This hacks the .git to do migration https://git-scm.com/book/en/v2/Git-and-Other-Systems-Migrating-to-Git This is a more manual apprach: # # Create migration directory # mkdir ~/GitMigration cd ~/GitMigration # # Create a map of svn -> git users # fix short-name -> long-name, and fix eamil # cat authors.txt chris = Chris Onefish john = John Twofish sue = Sue Redfish # # Initial conversion # time git svn clone --stdlayout --authors-file=authors.txt https://svn.my.domain.com/MYREPO MYREPO # # Look at what it created # cd MYREPO/ git branch -r origin/0.1.0 origin/1.0.0 origin/1.0.1 origin/1.1.0 origin/1.1.1 origin/1.2.0 origin/1.2.1 origin/2.0.0 origin/tags/1.0.0 origin/tags/1.1.0 origin/tags/1.2.0 origin/tags/1.2.1 origin/trunk git branch master git tag # # Create Gitblit account and clone it # Log into gitbit as admin. Create MYREPO # # Add remote to our converted clone # cd MYREPO GIT_URL='ssh://admin@git.mydomain.com:12345/MYREPO.git' git remote add gitblit "$GIT_URL" # # Convert things to proper branches and tags. # I can use the dry-run output to figure out the correct refspec # git push gitblit refs/remotes/origin/0.1.0:refs/heads/0.1.0 git push gitblit refs/remotes/origin/1.0.0:refs/heads/1.0.0 git push gitblit refs/remotes/origin/1.0.1:refs/heads/1.0.1 git push gitblit refs/remotes/origin/1.1.0:refs/heads/1.1.0 git push gitblit refs/remotes/origin/1.1.1:refs/heads/1.1.1 git push gitblit refs/remotes/origin/1.2.0:refs/heads/1.2.0 git push gitblit refs/remotes/origin/1.2.1:refs/heads/1.2.1 git push gitblit refs/remotes/origin/2.0.0:refs/heads/2.0.0 git push gitblit refs/remotes/origin/tags/1.0.0:refs/tags/1.0.0 git push gitblit refs/remotes/origin/tags/1.1.0:refs/tags/1.1.0 git push gitblit refs/remotes/origin/tags/1.2.0:refs/tags/1.2.0 git push gitblit refs/remotes/origin/tags/1.2.1:refs/tags/1.2.1 # # Verify # cd ~/GitMigration git clone $GIT_URL git_test cd git_test git branch -r origin/0.1.0 origin/1.0.0 origin/1.0.1 origin/1.1.0 origin/1.1.1 origin/1.2.0 origin/1.2.1 origin/2.0.0 git tag 1.0.0 1.1.0 1.2.0 1.2.1 # # Done # #========================================= # Get rev number from git. # I like human readable revision numbers #========================================= Command: git rev-list --count HEAD Returns: number of commits to this branch. If there is no way for rev 1 to come after rev 2, then I'd say this takes one issue out of my bag of issues, so I'll have to play with with it. #========================================= # # create a pull request # #========================================= # look at the current state of things git remote -v johnstile git@github.com:johnstile/PyClass-lesson-plans.git (fetch) johnstile git@github.com:johnstile/PyClass-lesson-plans.git (push) origin git@github.com:PyClass/PyClass-lesson-plans.git (fetch) origin git@github.com:PyClass/PyClass-lesson-plans.git (push) git branch cherrypick * master # Get wordlist from http://www.newgeneralservicelist.org/ # Create ngsl1.01.csv # Add to my master git add ngsl1.01.csv git commit ngsl1.01.csv [master ca0301e] adding ngsl1.01.csv 1 file changed, 1 insertion(+) create mode 100644 21_decoding_fun/ngsl1.01.csv # push to my github git push johnstile Warning: untrusted X11 forwarding setup failed: xauth key data not generated Warning: No xauth data; using fake authentication data for X11 forwarding. X11 forwarding request failed on channel 0 Counting objects: 393, done. Delta compression using up to 4 threads. Compressing objects: 100% (243/243), done. Writing objects: 100% (393/393), 197.50 KiB | 0 bytes/s, done. Total 393 (delta 203), reused 260 (delta 143) To git@github.com:johnstile/PyClass-lesson-plans.git a03a8aa..ca0301e master -> master # First stash my changes git stash Saved working directory and index state WIP on master: ca0301e adding ngsl1.01.csv HEAD is now at ca0301e adding ngsl1.01.csv git status .... numerous .... .... numerous modified files .... .... no files staged for commit .... # # this checks out a branch at the revision I pulled last pulled from # git checkout -b pickabranchnamehere 540558a warning: unable to rmdir 6_socrata_matplotlib_workshop/getsocrata: Directory not empty Switched to a new branch 'pickabranchnamehere' git status . On branch pickabranchnamehere Untracked files: .... numerous .... .... no modified files .... .... no files staged for commit .... # Pull in just the commit git cherry-pick ca0301 [pickabranchnamehere 13e9be3] adding ngsl1.01.csv 1 file changed, 1 insertion(+) create mode 100644 21_decoding_fun/ngsl1.01.csv # just showing what branch I am on git branch cherrypick master pick * pickabranchnamehere # push my changes to my github (they will pull from this) git push johnstile Warning: untrusted X11 forwarding setup failed: xauth key data not generated Warning: No xauth data; using fake authentication data for X11 forwarding. X11 forwarding request failed on channel 0 Counting objects: 2, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 260 bytes | 0 bytes/s, done. Total 2 (delta 1), reused 0 (delta 0) To git@github.com:johnstile/PyClass-lesson-plans.git * [new branch] pickabranchnamehere -> pickabranchnamehere # # On the github web site, # # go to their url: https://github.com/PyClass/PyClass-lesson-plans # Click "Pull Request" # Click the Green "New pull request" button # Click the "compare across forks" # base fork: Pyclass/PyClass-lesson-plans, base:master # head fork: johnstile/PyClass-lesson-plans, compare:pickabranchnamehere # # click the big green "create pull request' button # you can now add a description, comment, but all that is all optional # the puller may add a comment requesting more chagnes. # #========================================= great interaticve git tutorial #========================================= http://pcottle.github.io/learnGitBranching/ http://learn.github.com/p/intro.html Github learning course #----------------------------- Create branch release-1.1.0 from branch release-1.0.0 git clone git@devel.mydomain.com:foo.git -b release-1.0.0 cd foo/ git checkout -b release-1.1.0 git push origin release-1.1.0 #----------------------------- Intro: URL: http://git-scm.com/downloads git help # dumps all verbs git help # help for git log # shows all commits git log -p # shows patch git is distributed via full clones this means many commands work off the local host much work can be cone off line commands are fast space is smaller (depends on binaries) # list branches git branches # create a branch git checkout -m mybranch # switch to master branch git checkout master #----------------------------- Setup and Initiaization # Setup global username git config --global user.name "John Stile" # set email git config --global user.EMAIL "john@stilen.com" # setup editor git config --global core.editor "komodo" # show all config git config --list # Setup local username and email git config user.name "John Stile" git config user.EMAIL "john@stilen.com" # show user/email git config user.name git config user.email # local stores in .git/config # global cat ~/.gitconfig [user] name = John Stile email = johns@foo.bar [color] ui = auto [alias] st = status [diff] tool = /usr/bin/meld external = /home/jstile/bin/diff.py # create new git repository git init # creates .git, but not under every subdirectory ls -la total 83 drwxr-xr-x 7 jstile 1000 432 Oct 25 17:20 . drwxr-xr-x 9 jstile 1000 328 Aug 30 10:36 .. -rw-r--r-- 1 jstile 1000 2344 Oct 3 13:45 COMMIT_EDITMSG -rw-r--r-- 1 jstile 1000 273 Feb 21 2012 config -rw-r--r-- 1 jstile 1000 73 Feb 21 2012 description -rw-r--r-- 1 jstile 1000 0 Dec 13 13:15 FETCH_HEAD -rw-r--r-- 1 jstile 1000 23 Aug 28 11:57 HEAD drwxr-xr-x 2 jstile 1000 504 Sep 27 00:58 hooks -rw-r--r-- 1 jstile 1000 34144 Oct 3 13:45 index drwxr-xr-x 2 jstile 1000 72 Feb 21 2012 info drwxr-xr-x 3 jstile 1000 96 Feb 21 2012 logs drwxr-xr-x 259 jstile 1000 6216 Aug 30 10:36 objects -rw-r--r-- 1 jstile 1000 41 Oct 3 12:45 ORIG_HEAD -rw-r--r-- 1 jstile 1000 94 Feb 21 2012 packed-refs -rw-r--r-- 1 jstile 1000 14559 Apr 11 2012 qgit_cache.dat drwxr-xr-x 5 jstile 1000 120 Feb 21 2012 refs # add all directories and subdirs git add . # initial commit git commit -m 'initial checkin' git status git log # clone a git git clone git://github.com/smtlaissezfair/calendar_helper.git git_calendar_helper URL protocols: public repository - http:// public repository - git://github.com/smtlaissezfair/calendar_helper.git git_calendar_helper private repository - git@github.com/smtlaissezfair/calendar_helper.git git_calendar_helper #----------------------------- Normal Workflow modify files see what you changed stage the changes you want to commit commit your staged changes rinse, repeat #------------------------------------------------------------------------------ BRANCHING HOWTO: http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging #------------------------------------------------------------------------------ Made changes locally, ran commit and push Error: “Your branch is ahead of 'origin/master' by 2 commits.” I don't want to toss our my changes. git diff origin/master shows lots of changes git remote show origin * remote origin Fetch URL: ssh://git@devel.mydomain.com/testing.git Push URL: ssh://git@devel.mydomain.com/testing.git HEAD branch: master Remote branches: master tracked single_cal tracked Local branch configured for 'git pull': master merges with remote master Local ref configured for 'git push': master pushes to master (fast-forwardable) Solution: # 1. Copy all branches from the remote refs/heads/ namespace and stores them to the local git fetch origin # 2. Move my commits to the "top" git rebase origin/master # 3. Push my changes to the remote git push origin master #--------------------------------------------- # Windows users #--------------------------------------------- Steps to work with the git repository: Install windows git client https://git-for-windows.github.io/ click Download Run installer Accept default path Select components Add icon to desktop Windows Explorer indegration x Git Bash Here x Git GUI Here x Associate .git config... x use true type fonts Select start menu folder: Git Adjust your path env x "Use Git from the Windows Command Prompt" x "Checkout Windows-style, commit Unix-style line endings Accept defaults for for other options. Finish end installer. Generate ssh key pair double click "Git Bash" icon on the desktop. Type: ssh-keygen Click until you are back at the prompt (accept defaults for everything) Note the path to your public and private keys: Type: cat $HOME/.ssh/id_rsa.pub Select the output of that command by holding down the left mouse button and drag over the text, and right click the text and chose copy. Your public key is now copied in the clipboard buffer. Log into gibilit server, change your password, and upload your .pub key Click person icon in upper right corner. select "Change password" Click person icon in upper right corner. select "my profile" select "SSH Keys" under "Add SSH Key", paste the content of your public key Click the "Add" button * now you can clone the rep Brows to "repositories" Click the you will see what you have access to. Pick on You should see the git clone url like the one in the attached image. Copy that url. ssh://@/.git In your git bash shell, do the following git clone --recursive ssh://@/.git git_myrepo I like to prefix my git clones with 'git_' to help distinguish them from from a normal folder. Using your file Explorer, right click your git_myrepo folder. Choose Git Gui Here This might be easier than reading the git manual. There are other gui git clients for windows, but they will all work on the same directory. #----------------------------------------------- # # Merge a commit from one branch into another. # git checkout origin/beta1-v1.0.2 * this gave me a detached HEAD git checkout beta1-v1.0.2 * this seemed to solve my detached HED git cherry-pick 06a30e git push #----------------------------------------------- # # Checkout tag named v8.2.1 # git fetch --all --tags --prune git checkout tags/v8.2.0 #----------------------------------------------- # # Find remote branches containing a commit # git branch -r --contains 5d0c61bb27c6bf7bcec29c26f7f04c2692506680 origin/HEAD -> origin/master origin/master #----------------------------------------------- # # Remove all untracked files and directories. (`-f` is `force`, `-d` is `remove directories`) # git clean -fd #----------------------------------------------- # # Revert changes to modified files. # git reset --hard #----------------------------------------------- # # Diff file in two branches # git diff master beta1-v1.0.2 -- software/apps/compass/EUROPA/Source/autobuild/win/build_and_package.bat # # Random # git reflog gitk git checkout --theirs path/to/file git checkout --ours path/to/file git rebase --continue git merge --ff-only major_refactor git pull --ff-only origin master git fetch --all -p origin && git log master ^origin/master --no-merges git log master..major_refactor git reset --hard origin/master git checkout major_refactor git push -v origin +refs/heads/major_refactor:refs/heads/master git push -d origin major_refactor #------------------------------------------------------- # Merge back to master with rebase #------------------------------------------------------- # # Update to local branch with remote branch of same name # git checkout refactor_branch origin refactor_branch # # Ensure no changes or uncommitted issues # git status # # Start rebase # Find the common ancestor commit between branches # Rewinds refactor_branch to last common ancestor between branches # From the common ancestor commit, apply all commits in master up to HEAD # One by one, apply refactor_branch commits after master HEAD # Stop on each conflict until resolve. # Resolve conflicts # Resume rebase # git pull --rebase origin master # # Look for errors, Record list of files under 'Unmerged paths:' # git status # # For each file, change to resolve the conflict # edit myfile1 edit myfile2 edit myfile3 # # Once all the file conflicts are resolved, issue an add and rebase continue # git add git rebase --continue git status # # Repeat until no more errors. # Eventually rebase completes without error. # # # Check history # git log # # Push changes to mater # git push origin refs/heads/refactor_branch:refs/heads/master # # Check the remote server to verify the history # # # Remove remote branch # git push origin -d refactor_branch # # Remove local branch # git branch -D refactor_branch #========================== Manage Conflict: #------------------------------- # Conflicted happens at 2 points: # 1) fail starting merge # 2) fail during merge 1. fail starting merge error: Entry '' not uptodate. Cannot merge. (Changes in working directory) Reason: Incoming Merge could overwrite Pending change in working or staging Fix: Stabilize local state with: git stash git checkout git commit git reset --mixed # Reset index, changed files are preserved, but not marked for commit git reset --hard # Reset index, changed files are reverted 2. fail during merge error: Entry '' would be overwritten by merge. Cannot merge. (Changes in staging area) Reason: Incomming Merge branch conflicts with current local branch Fix: Manual intervention git merge --abort Edit file manually, git add, and conginue git reset Example: Bring unshared branch up to date with parent Cmd: git pull --rebase origin master error: Failed to merge in the changes. Reason: Branch is no longer directly based off parent history File history changes in both branches Fix: Manually replay each commit until resolved * This rewrites this branch history, putting parent first * This is why frequently --rebases from parent branch git mergetool --tool=meld git add README.md git rebase --continue git add READM.md git rebase --continue Example: Bring shared branch up to date with parent Cmd: git pull --ff-only origin master fatal: Not possible to fast-forward, aborting. Reason: Branch is no longer directly based off parent history File history changes in both branches Fix: Inspect && Fetch && Merge && Commit Inspect: Look at differnce git diff Find recent common ancestor git merge-base origin/master . git log --graph --oneline --all Find oldest common ancestor git rev-list --first-parent origin/master If we can take theirs or yours, no extra merge git pull -X theirs If in conflict already git checkout -X theirs Otherwise merge the two and make a commit: git mergetool --tool=meld #Answer merge was successful # This should have called 'git add ' git commit -m 'this is my pesky merge comment' # if you are happy, then pushit, but look at 'git log' commits git rev-list origin/master..HEAD --format=%B #------------------------------- Create Conflict: mkdir git_merge_test cd git_merge_test git init . echo "This is some stuff" >> merge.txt git add merge.txt git commit -am "we are committing the initial context" git checkout -b new_branch_to_merge_later echo 'Totally different content' > merge.txt git commit -am "changed content of merge.txt" git checkout master echo 'Yet anohter change' >> merge.txt git commit -am 'Append content to merge.txt' # The Big Moment: git checkout new_branch_to_merge_later git rebase master Auto-merging merge.txt CONFLICT (content): Merge conflict in merge.txt error: could not apply 88b4614... changed content of merge.txt Resolve all conflicts manually, mark them as resolved with "git add/rm ", then run "git rebase --continue". You can instead skip this commit: run "git rebase --skip". To abort and get back to the state before "git rebase", run "git rebase --abort". Could not apply 88b4614... changed content of merge.txt # commands: git log --diff git diff cat merge.txt <<<<<<< HEAD This is some stuff Yet anohter change ======= Totally different content >>>>>>> 88b4614... changed content of merge.txt git status interactive rebase in progress; onto 82eae6d Last command done (1 command done): pick 88b4614 changed content of merge.txt No commands remaining. You are currently rebasing branch 'new_branch_to_merge_later' on '82eae6d'. (fix conflicts and then run "git rebase --continue") (use "git rebase --skip" to skip this patch) (use "git rebase --abort" to check out the original branch) Unmerged paths: (use "git restore --staged ..." to unstage) (use "git add ..." to mark resolution) both modified: merge.txt no changes added to commit (use "git add" and/or "git commit -a") #------------------------------- Resolve Conflict: vi merge.txt # Remove <<<<<<<, =======, >>>>>>> git add merge.txt git rebase --continue # Add commit message git status . On branch new_branch_to_merge_later nothing to commit, working tree clean #==========================