Git A distributed version control system Powerpoint credited
Git A distributed version control system Powerpoint credited to University of PA And modified by Pepper 15 -Sep-20
Version control systems n Version control (or revision control, or source control) is all about managing multiple versions of documents, programs, web sites, etc. n n n Some well-known version control systems are CVS, Subversion, Mercurial, and Git n n n Almost all “real” projects use some kind of version control Essential for team projects, but also very useful for individual projects CVS and Subversion use a “central” repository; users “check out” files, work on them, and “check them in” Mercurial and Git treat all repositories as equal Distributed systems like Mercurial and Git are newer and are gradually replacing centralized systems like CVS and Subversion 2
Why version control? n For working by yourself: n n n For working with others: n n Gives you a “time machine” for going back to earlier versions Gives you great support for different versions (standalone, web app, etc. ) of the same basic project Greatly simplifies concurrent work, merging changes For getting an internship or job: n n Any company with a clue uses some kind of version control Companies without a clue are bad places to work 3
Download and install Git n There are online materials that are better than any that I could provide n n n Install Git on your machine from http: //git-scm. com/downloads n n Standard one: http: //git-scm. com/downloads Here’s one from Stack. Exchange: http: //stackoverflow. com/questions/315911/git-for-beginners-the-definitive -practical-guide#323764 Accept context menu items Git access: n n Right click from windows explorer git. Bash to enter commands 4
Introduce yourself to Git n n Start git / git. Bash Enter these lines (with appropriate changes): n n git config --global user. name "John Smith" git config --global user. email jsmith@seas. upenn. edu You only need to do this once If you want to use a different name/email address for a particular project, you can change it for just that project n n cd to the project directory Use the above commands, but leave out the --global 5
Choose an editor n n When you “commit, ” git will require you to type in a commit message For longer commit messages, you will use an editor The default editor is probably vim To change the default editor: n n You may also want to turn on colors: n n git config --global core. editor /usr/bin/vim git config --global color. ui auto See your options: n git config -l 6
Your repositories n We have created just 1 git repository so far, but plan to create more if you want to use panther's git. n ssh: //pepper@panther. adelphi. edu/opt/git/csc 480 ASpring 15. git n 7
Using your repositories on panther n Get the files from your repository before starting n Make a local respository as a clone of master n n n git clone /opt/git/csc 480 ASpring 15. git See all the contents of the folder n ls -a to see the. git folder. Make changes n See what changed n n git diff Stage changes n n n git add –all (or particular files) git diff –cached Still only in your repository 8
Using your repository n Put changes back up into repository n Commit your staged changes in your repository n n Update the respository: n n git push origin See what is on the repository n n git commit -m "the reason for the change" git remote Get what is on repository n n git pull If it says to resolve manually, just vi that file and see the head which is yours 9
Typical workflow n git pull remote_repository n n git status n n n Get changes from a remote repository and merge them into your own repository See what Git thinks is going on Use this frequently! Work on your files git add –-all (or just changes) git commit –m “What I did” git push 10
Helpful git. Bash commands n n n n Show staged differences: git diff -- cached Show status : git status Show branches: git branch See history: git log Checkout a branch: git checkout branch Fetch so you can look but maybe not take: git fetch Pull will fetch and merge with what you have: git merge 11
Git log commands n git log n n n --pretty=oneline --max-count=2 git log --pretty=oneline --since='5 minutes ago' git log --pretty=oneline --until='5 minutes ago' git log --pretty=oneline --author=<your name> git log --pretty=oneline –all 12
Git log pretty n git log --pretty=format: "%h %ad | %s%d [%an]" --graph -date=short --pretty=". . . " defines the output format. n %h is the abbreviated hash of the commit n %d commit decorations (e. g. branch heads or tags) n %ad is the commit date n %s is the comment n %an is the name of the author n --graph tells git to display the commit tree in the form of an ASCII graph layout n --date=short keeps the date format short and nice n 13
Good aliases n n n n n alias gs='git status ' alias ga='git add ' alias gb='git branch ' alias gc='git commit' alias gd='git diff' alias go='git checkout ' alias gk='gitk --all&' alias gx='gitx --all' alias got='git ' alias get='git ' 14
- Slides: 14