Git Control: Basics of Git For Developers and System Administrators
Git Control: 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
REASONS TO USE GIT
• Installed by default on modern *nix Operating systems, but may still want to
grab latest version
• https://git-scm.com/downloads
• May also consider GUI client
• SourceTree (free, Mac and Win)
https://www.sourcetreeapp.com/
CONFIGURING GIT
• From the command line, Make and/or navigate to the directory/folder for Git
to track
• Type the command:
• git init
GIT COMMANDS
• git status
• git add <file>
• git add .
• 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
GIT COMMANDS (CONTINUED)
• 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 username@computername
TYPICAL DAY WITH GIT
Really Good Day Not so Good Day
• git fetch <remote> <feature branch> • git fetch <remote> <feature branch>
• Or git pull • Work on code
• Work on code • Get stuck
• git status • git status
• git add <file(s) I worked on/edited> • git add <file(s) I worked on/edited>
• git commit –m “<message about what I fixed • git checkout –b <remote> <nameForNewBranch>
with maybe a tag for ticket closure or release>” • git commit –m “[WIP]<what I was trying to fix and
• git fetch <remote> <feature branch> my attempted approach>”
• merge/Resolve differences • Pull Request (aka Merge Request) to teammate
• git push <remote> <feature branch> • Receive feedback/help/resolution --> unstuck
• Submit a Pull Request for approval • Continue on with Really Good Day workflow
WORKING WITH A TEAM IN GIT VS ALONE
TEAM ALONE
• Make sure editor/IDE configured for team • Commit often and feel free to push every
agreed upon line lengths
time as it creates a backup of your code
• Commit often, but generally push working
code that fixes an issue or completes feature • Only need to fetch and merge changes if
• Make sure to fetch prior to push to then you had pushed work from another
merge in any changes that have occurred on computer to the remote
the remote
• Pull requests allow you to ask someone to • This is when to try out and learn about
review your code for approval, but don’t rebasing (only on private branches)
forget it can also be helpful for asking for
help if you get stuck
• More prescribed branching
! Do NOT rebase on public branch
GIT BRANCHING
Source: https://leanpub.com/git-flow/read
GIT TIPS
• 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
GIT FOR SYSTEM ADMINISTRATORS