1 / 34

CReSIS Git Tutorial

CReSIS Git Tutorial. CReSIS Git Tutorial. • Git: a distributed version control system • Distributed means that each person holds the entire repository locally • This means you have a local copy of all versions of your project files • Topics • Installation

lahey
Télécharger la présentation

CReSIS Git Tutorial

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CReSIS Git Tutorial

  2. CReSIS Git Tutorial • Git: a distributed version control system • Distributed means that each person holds the entire repository locally • This means you have a local copy of all versions of your project files • Topics • Installation • Configuration (git config …) • How to get a copy of another repository (git clone) • Get updates from another repository (git pull) • Commit your changes (git commit) • Send your commits to another repository (git push) • Other common tasks • Windows Server • Remote Git SSH Access • Link a repository for a different project into a repository • https://www.atlassian.com/git/tutorials/ • https://git-scm.com/doc <-- Git Home Page

  3. Installation • Install “git for windows” • IMPORTANT: Choose all the default settings except for the ones described on the next few slides. • Install “TortoiseGit” • Choose all the default settings. • If software is not available from the “Software Center”, you will need to email helpdesk to have them install it.

  4. Installation: Git For Windows Field Installation Where Windows SSH Server Will Be Required Normal Installation

  5. Installation: Git For Windows Do not commit files with CRLF (carriage return – line feed).

  6. Configuration (git config …) • Your global git configuration settings are stored in your user directory in the “.gitconfig” file. • Windows: C:\Users\USERNAME\.gitconfig • Linux: /users/USERNAME/.gitconfig/ • git setup: • You can edit your .gitconfig file using the “git config” command: • git config --global color.ui auto • Or you can just edit it directly: [user] name = FIRST LAST email = KU_EMAIL_ADDRESS [alias] lgb = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset%n' --abbrev-commit --date=relative --branches [color] ui = auto

  7. Configuration (git config …): TortoiseGit Username and Email Shortcut to edit “.gitconfig” Remember password

  8. How to get a copy of another repository (git clone) • git clone https://git.cresis.ku.edu/dangermo/cresis-toolbox.git • git clone https://GITUSERNAME@git.cresis.ku.edu/dangermo/cresis-toolbox.git • For KU CReSIS accounts, “cd ~/scripts/” first • Using TortoiseGit you right click in your \users\USERNAME\documents\scripts directory and choose “git clone” and then paste above address into URL field. • git checkout dev • Switch to branch “dev”. • To create a new repository in any directory: • git init

  9. How to get a copy of another repository (git clone) • You can git clone from any repository. • Three ways to specify the repository: • https: (must have server that supports this) • https://github.com/CReSIS/OPS.git • https://git.cresis.ku.edu/dangermo/cresis- toolbox.git • ssh: (any machine running ssh) • paden@ssh.cresis.ku.edu:443:scripts/cresis- toolbox/ • git@github.com:CReSIS/OPS.git • The file path on the remote machine is given after the colon. • file path: • E:\Documents\scripts\cresis-toolbox

  10. How to get a copy of another repository (git clone) • When you clone a repository you get everything for the specified branch. • To pass changes back and forth between repositories we use the “push” and “pull” commands. You just have to tell git where the repository exists (can be an ssh server, https server, or a directory on a file system). • Only committed changes can be pushed and pulled. • If you make changes that you want to share or a particular version (snapshot of all files) that you may want to refer back to, you “commit” your changes. • If another person commits a file you are trying to commit, you will have to merge in their changes and commit this merge before you are allowed to push your commits.

  11. How to get a copy of another repository (git clone) • Change your active branch to “dev”

  12. Get updates from another repository (git pull) • git pull • Gets any new commits and adds them to your repository • Without arguments, it assumes: • “origin” for the remote repository (short cut for the original repository that you cloned from… although you can change it manually too). • Current active branch • You can git pull from any repository. • See previous page on cloning to see how to specify other repositories.

  13. Get updates from another repository (git pull) • git pull • Gets any new commits and adds them to your repository • Without arguments, it assumes: • “origin” for the remote repository (short cut for the original repository that you cloned from… although you can change it manually too). • Current active branch • You can git pull from any repository. • See previous page on cloning to see how to specify other repositories.

  14. Get updates from another repository (git pull) • git pull • Gets any new commits and adds them to your repository • Without arguments, it assumes: • “origin” for the remote repository (short cut for the original repository that you cloned from… although you can change it manually too). • Current active branch • You can git pull from any repository. • See previous page on cloning to see how to specify other repositories.

  15. Git Commit: “Stage” or select which files you want to commit. • TortoiseGit: • Staging and committing are all one step and the graphical user interface is intuitive. • Make sure to select only the files you want to commit. • Check diff on each file by double clicking on the file and opening in TortoiseGitMerge. • Command line: • git add FILENAME, git add -u (adds all tracked files) • git add –i • Interactive mode. Example is to add all untracked files. • First you select which files you want. For example “a” for untracked. • Then select which of those you want to add. For example, “*” for all. • Then quit “q”. • git status • Tells you which files you have added • git reset FILENAME • Unstages a file • git reset • Unstages all files • git commit

  16. Git Commit: “Stage” or select which files you want to commit. • TortoiseGit: • Staging and committing are all one step and the graphical user interface is intuitive. • Make sure to select only the files you want to commit. • Check diff on each file by double clicking on the file and opening in TortoiseGitMerge. • Command line: • git add FILENAME, git add -u (adds all tracked files) • git add –i • Interactive mode. Example is to add all untracked files. • First you select which files you want. For example “a” for untracked. • Then select which of those you want to add. For example, “*” for all. • Then quit “q”. • git status • Tells you which files you have added • git reset FILENAME • Unstages a file • git reset • Unstages all files • git commit

  17. Send your commits to another repository (git push) • Just like git pull only you are sending your commits to another repository. In fact, it is almost identical to having the other repository do a git pull from your repository.

  18. Send your commits to another repository (git push) • Just like git pull only you are sending your commits to another repository. In fact, it is almost identical to having the other repository do a git pull from your repository.

  19. Other: Undo changes • Undo commits from “mybranch” • git checkout mybranch • If you have not already pushed the commits, you can just delete them completely from the history: • git reset --hard HEAD~2 • Moves back 2 commits and removes all working directory changes • HEAD is a short cut to the most recent commit on your checked out branch • If you have pushed the commits you are trying to undo, then you should create a new commit with the changes removed: • git revert --no-commit HEAD~2..HEAD • Reverts last 3 commits • git commit --message “Revert last two commits” • If you have pushed a commit that was a merge that you are trying to undo, then you need to choose the correct parent to revert to (use “git log” to see the list of parents): • $ git log commit c66e84975765bc5274a649c393187c25a3ba5bde Merge: b75a504 e403d46  PARENTS ARE LISTED HERE • git revert -m 1 --no-commit HEAD  -m 1 chooses “b75a504” • Just undo working directory changes (there is no way to undo these commands with git) • git reset --hard HEAD # Resets the whole repository • git checkout -- FILE # Resets a specific file • git clean -d –f # Removes untracked files and directories • UnstageFiles • • git reset HEAD FILENAME git reset • Unstages all files • Amend a previous commit • git commit --amend

  20. Other: Stashing • “Stashing” changes so you can switch branches even though your working directory is in a dirty state (you have modified tracked files and staged changes). • Stashing is necessary for a “git pull” which brings in commits on files which conflict with your modifications. • TortoiseGit: Usually just use “Stash Save” and “Stash Pop” • git stash • Stashes • git stash list • git stash apply stash@{1} • Applies changes from your stash • git stash drop stash@{1} • Drops a particular stash (do this when you no longer need it) • git stash show -p stash@{0} | git apply –R • Undoes a stash (-R applies in reverse … which means it undoes the changes) • “Show -p” prints the changes associated with the particular stash to stdout

  21. Other: Stashing • “Stashing” changes so you can switch branches even though your working directory is in a dirty state (you have modified tracked files and staged changes). • Stashing is necessary for a “git pull” which brings in commits on files which conflict with your modifications. • TortoiseGit: Usually just use “Stash Save” and “Stash Pop” • git stash • Stashes • git stash list • git stash apply stash@{1} • Applies changes from your stash • git stash drop stash@{1} • Drops a particular stash (do this when you no longer need it) • git stash show -p stash@{0} | git apply –R • Undoes a stash (-R applies in reverse … which means it undoes the changes) • “Show -p” prints the changes associated with the particular stash to stdout

  22. Other: Branching • To create a new branch: git checkout -b newbranch • Short for git branch newbranch; git checkout newbranch; • git fetch origin NEWBRANCH • git checkout NEWBRANCH; git merge master • OR git checkout master; git merge NEWBRANCH • OR git pull origin rss (pulls rss branch and merges it) • git branch -d NEWBRANCH • Works if fully merged. To override protection use -D: git branch -D NEWBRANCH

  23. Resolving Conflicts • TortoiseGit: Use TortoiseMerge • Linux: Just edit the files that are conflicted and then commit them. Conflicted files will have conflict blocks in them which have to be manually removed/edited.

  24. Windows Server • Install “Bitvise ssh” • Commands to access it from Linux Server assuming “10.0.0.10” is the IP address of your Windows Server: • git clone awi@10.0.0.10:cresis-toolbox.git • git remote add origin awi@10.0.0.10:cresis-toolbox.git • git push • git pull • To push changes to the Windows Server, you will need to checkout a different branch on the windows server before it will allow pushes to it.

  25. Windows Server: Create user

  26. Windows Server: SSH Server Settings

  27. Windows Server: SSH Server Settings

  28. Windows Server: SSH Server Settings

  29. Windows Server: SSH Server Settings

  30. Windows Server: Settings of toolbox folder

  31. Windows Server: Verify Path Set

  32. Remote Git SSH Access • Generate Key • ssh-keygen -t rsa -C paden@ku.edu • Save the key in the default location ~/.ssh/id_rsa • Add public key (cat ~/.ssh/id_rsa.pub) on git.cresis.ku.edu Gitlab website • Add the key here: DashboardProfile SettingsSSH Keys • git.cresis.ku.edu ssh server opened to the world on port 62: • git remote add origin ssh://git@git.cresis.ku.edu:62/dangermo/cresis- toolbox.git

  33. Remote Git SSH Access • Steps to setup tunnel: no longer required since git server is setup on port 62 • Setup Tunnel to SSH Server • ssh -L12001:git.cresis.ku.edu:22 -p 443 paden@ssh.cresis.ku.edu • Create ~/.ssh/config file with the following contents: Host git.cresis.ku.edu HostName localhost User git Port 12001 IdentityFile ~/.ssh/id_rsa • git clone git@git.cresis.ku.edu:dangermo/cresis-toolbox.git

  34. Link a repository for a different project into a repository • git submodule add git@git.cresis.ku.edu:mxu/cresis-music-3d.git cresis- toolbox/+tomo/optim_tracker/ • If cloning a repository with submodules, you will need to run: • git submodule init • git submodule update • OR just do git clone --recursive • To grab a new commit/version from the submodule: • git submodule update --remote • To specify a branch besides master • git config –f .gitmodules submodule.cresis-music-3d.branch dev • Then git submodule update –remote • If you switch to a branch without the submodule and need to remove it: • git clean –fdx • To remove a submodule: • git submodule rm optim_tracker

More Related