Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basics of GIT for developers and system administrators

Similar presentations


Presentation on theme: "Basics of GIT for developers and system administrators"— Presentation transcript:

1 Basics of GIT for developers and system administrators
GIT Control Basics of GIT for developers and system administrators Jennifer Watson System Engineer University of Maine System NECWIC 2017

2 Reasons to USE GIT Working on complex code project
Working on code from more than one computer Collaborating with others on code or text file Maintain version control on code or file Be able to see when code or configuration files have changed and be able to note/read why it was changed Want to compare or merge different versions Be able to roll back quickly to last known working version after changes break something Distributed copies of code or file provide back up in case of lose

3 Installing GIT Installed by default on modern *nix Operating systems, but may still want to grab latest version May also consider GUI client SourceTree (free, Mac and Win)

4 Configuring GIT From a command line:
git config –global user.name “FirstName LastName” git config –global user. git config –global color.ui “auto” Mac/linux git config – global core.editor “nano –w” Windows git config –global core.editor “’c:/program files (x86)/Notepad++/notepad++.exe’ –multiInst –notabbar –nosession noPlugin” git config --list

5 Create a GIT Repository
From the command line, Make and/or navigate to the directory/folder for Git to track Type the command: git init

6 GIT COMMANDS git status git add <file> git commit –m “message”
git log --graph git diff git diff –staged git diff HEAD~1 (can substitute 3 version back you want to compare to current version) git diff CommitIHash

7 GIT commands (continued)
git checkout <branch> switch branches git checkout HEAD~1 Reverts to previously committed version can be used to undelete a file git reset HEAD <file> Un-stage file git reset --hard Everything reverted to last commit ! Be careful with reset commands

8 aka Staging Notice the difference between pull and fetch

9 Working with remote repositories
git clone <url> git remote add <remote> <url for repository on gitLab or ssh link> git remote –v Lists existing remotes git fetch <remote> <branch> Recommend using fetch instead of pull git push <remote> <branch>

10 Using REMOTES with ssh cd ~/.ssh ssh-keygen
Open the rsa.pub file created and copy the contents to your remote repository Begins with ssh-rsa and ends with

11 Typical Day with Git Really Good Day
git fetch <remote> <feature branch> Or git pull Work on code git status git add <file(s) I worked on/edited> git commit –m “<message about what I fixed with maybe a tag for ticket closure or release>” merge/Resolve differences git push <remote> <feature branch> Submit a Pull Request for approval Not so Good Day git fetch <remote> <feature branch> Work on code Get stuck  git status git add <file(s) I worked on/edited> git checkout –b <remote> <nameForNewBranch> git commit –m “[WIP]<what I was trying to fix and my attempted approach>” Pull Request (aka Merge Request) to teammate Receive feedback/help/resolution --> unstuck  Continue on with Really Good Day workflow

12 Working with a Team in GIT vs Alone
Make sure editor/IDE configured for team agreed upon line lengths Commit often, but generally push working code that fixes an issue or completes feature Make sure to fetch prior to push to then merge in any changes that have occurred on the remote Pull requests allow you to ask someone to review your code for approval, but don’t forget it can also be helpful for asking for help if you get stuck More prescribed branching ALONE Commit often and feel free to push every time as it creates a backup of your code Only need to fetch and merge changes if you had pushed work from another computer to the remote This is when to try out and learn about rebasing (only on private branches) ! Do NOT rebase on public branch

13 Git Branching Source:

14 GIT TIPS Create .gitignore file in at root of git respository
List files to ignore Can use *.file-extension can still force add exceptions using git add – f file Great for excluding files your IDE may add to your Git tracked folder on your local computer Create hidden file in new folders you create with the following command: touch .gitkeep git cannot track an empty folder, so this is basically a placeholder file

15 Git for system administrators
git init on the folders with important configurations Know if someone else changed them by using git status And what they changed with git log and git diff Explain why you changed them with git commit –m “<reason>” so other admins will know Quickly bring back an earlier working version of the file with git checkout -- <file> Back up those key configurations easily by git push <remote> <branch> Note: git keeps track of changes NOT multiple copies of the file, so it does not take up a lot of space

16 Learning resources Code Academy More on How to Use in a Team team-environment/


Download ppt "Basics of GIT for developers and system administrators"

Similar presentations


Ads by Google