git cheat sheet cira software engineering group getting conguring git whatwasithinking reviewinghistory undoingchanges git is a freely available open source version control software for linux windows and mac gitgetsit you ...
Filetype PDF | Posted on 07 Feb 2023 | 2 years ago
Git Cheat Sheet—CIRA Software Engineering Group
Getting & configuring Git WhatwasIthinking‽—reviewinghistory&undoingchanges
Git is a freely-available, open-source version control software for Linux, Windows, and Mac. Gitgetsit—you&yourcollaboratorsaren’talwaysperfect. Browse&inspecthowthefilesintheproject
TogetGit, visit: https://git-scm.com/downloads. havechangedaswellaseraseyourmistakes.
✓ git --version ChecktheversionofyourGitinstallation " git log List version history for the currently checked out branch
git log --tags Amorehuman-readableversionof git log
Set and display Git local configuration information
" git config --list Display your current local Git configuration --decorate=full
git log --follow Display the history for a single file
git config --global user.name Sets the username associated with your commits
””
" git blame Addsuser&loginformationaboutfilechanges
git config --global Sets the email you want attached to your commits
user.email ”” " git diff Changesbetweenapreviouscommit¤tfilestate
" git config --global color.ui AddsasplashofcolortoGittomakeyourlifeeasier git diff Shows the changes in a file between branches. Note
... thatthe...blendsthedifferencesbetweenthetwover-
auto
sions together to make it easier to compare.
git config --global If you are not a fan of your system’s default, you can
core.editor changetheeditor(e.g., atom, vim, emacs) " git reset Removes the <file> from the staging area & keeps local,
unstagedchanges. Thisisa“mixed”modereset.
Wheretostart—settingupyourrepository
git reset Undoesallcommitsafterwhilekeepinglocal,
unstagedchanges
Initialize a new local repository, set up a remote, or clone an existing project along with its history.
" git init Creates a new local repository
git reset --hard “Hard” reset mode undoeschangesafterthe,
clears the staging area, & rewrites history
git remote add Createsalinktoaremoterepository(e.g.,ahostingservice
like GitHub or GitLab). isanaliasforthe
" git revert Leavescommithistoryintact, but restores/copies a previ-
& is typically set to ‘origin’. (-f fetches the remote
history during the add) ouscommitandsetsitasthemostrecent
git clean Removes untracked files from working directory (-n dis-
" git clone Creates a local copy of the repository on your machine
plays what will be removed; -f cleans the directory)
git clone -b Only clones a specific branch git checkout Restore a file to the previous commit
Makingachange—stage&snapshotyourchanges Keepingyourrepository up-to-date—managingremotes
Reviewyouredits, commitasnapshot,andtagyourprojectsprogress. Commandstoassistinsynchronizingyourlocalrepositorywithyourremote. Note:
" git status List which files have been modified or staged locally is the alias you set for the remote (e.g., ‘origin’) when you do a git remote add.
" git remote -v Lists the url & name of the remote fetch & push
git show Last commit&subsequentfilechangesinformation
git remote show Displays the remote url & detailed branch statuses
" git diff Showunstagedchangestoyourfile(s)
git remote set-url Changes the url for a specific remote name if it has been
previously set by git remote add
git diff --staged Showstaged,uncommittedchanges
git diff --cached Difference between staged changes and the last commit
git fetch Fetches the entire repository history from the remote
(adding branch only gets that specific branch)
" git add Addafilesnapshottoyournextcommit
" git pull Downloads the current working branch & merges it with
" git commit -m ”” Commityourstagedcontentasanewcommitsnapshot
local (to rebase rather than merge, add --rebase)
git commit --amend Replaceand/oreditthelastcommitbeforegit push
" git push -u Sendslocalbranchcommitstotheremote(--tagspushes
" git tag Liststherepository’stags(-ndisplaysnotes&messages) tags; --all uploads changes to every local branch)
git tag -a Flags the code with a version number and message
-m ””
Git Cheat Sheet—CIRA Software Engineering Group
Organizing patches & features—branches Incorporating snippets of code from other projects—subtrees
Creating branches isolates changes to your coding project while keeping your master branch stable. Afriend has an awesome script in version control that you want to add to your shiny, new repository.
" git branch Lists branches in the repository (an * proceeds the cur- Don’t copy it! Subtree it! Subtrees are repositories within repositories. Here are a few notes:
rent/working branch). -a shows remote branch names.
• Alwaysrunsubtreecommandsfromthetop/rootdirectoryofyourrepository.
git branch Creates a new branch
• Try not to modify the subtree’s code in the current repository. But, it can be done if necessary.
• DONOTUSEaleadingortrailing“/”forthesubtreedirectoryprefix;dir1/dir2issafe.
git branch -d Deletes the specified branch
• Alwaysuse--squashtokeepthesubtreerepositoryhistoryoutofyourhistory.
" git checkout Switchestherepository to the user defined branch
" git subtree add Insert a branch of a remote repository into the specified
git checkout -b Asinglestepcombiningcreating&checkingoutabranch
--prefix= subtreedirectorywithinyourcurrentrepository. Newre-
motescanbesetwithgit remote add.
Incorperating changes into the main branch—merging
--squash
Tomerge,ornottomerge,thatisthequestion—usefulcommandstoallowyoutocombinechangesin
git subtree pull Get the updated branch for the remote repository for the
yourcodewithotherbranchesinyourrepository. Oncethe‘feature’youaddedinyourbranchisstable,
--prefix= specifiedsubtree
youcanmergeaway!
" git merge Combine branch of the code you want to insert (add
--no-fftoprevent/resolvea“fast-forward”)
--squash
" git remote prune Removes dead wood by cleaning up deleted remote
Ingoring patterns & suppressing tracking—.gitignore
branchesinyourlocalrepository
Including a well-thought-out .gitignore file in your repository can save you a lot of time and
headaches. The .gitignore tells Git what patterns to avoid and prevent you from committing to
Spring cleaning—refactoring or removing files & paths
your repositories. Below are a few examples:
Need to relocate or completely remove files or directories? Then, we’ve got Git commands for you! " *.nc Addsawildcardglobtoavoidcommittingfileswiththeex-
Note: use Git to relocate or remove your file rather than OS-specific commands so that the change is
tension .nc
tracked.
" git rm Deletesthefileordirectoryfromyourlocalworkingrepos- temporary_* Addsawildcardglobforthepartialnameofafile
itory & stages the deletion for the next commit data/ Excludesthedirectory datafrombeingcommitted
git rm --cached keepsyourlocalcopy data
" git mv Changes the name of the file or directory and stages the " git ls-files -o -i Lists all ignored files in the repository (good to check to
--exclude-standard makesure something you want version controlled isn’t
changeforthenextcommit
being ignored)
" git filter-branch Removesthesnapshots of the file from your commit his- git add --force Addsasnapshotforanotherwiseignoredfile
--tree-filter ’rm -f tory. Warning: rewriting history will open a huge can of
’ HEAD worms—You’vebeenwarned!
Other useful Git resources
• http://swcarpentry.github.io/git-novice/
Temporarycommits&experimentalcodefragments—stashing
• https://rogerdudler.github.io/git-guide/
Puttingchangesonholdsoyoucandosomethingelse—let’sfaceit,multitaskingisnexttoimpossible. • https://www.atlassian.com/git/tutorials/
" git stash list List all current stash entries (e.g., changesets & stash ids) • https://git-scm.com/docs/gittutorial
• https://try.github.io/levels/1/challenges/1
git stash save ”” Saveandstoreyourchangesonalist
• Your favorite internet search engine or question-and-answer site (e.g., Stack Overflow)
git stash pop Applies a stash & removes it from the stash list
stash@{} " Indicates a Git command that is used frequently
git stash show -p Displays the differences between the branch & stashed
command AGitcommand
stash@{} changes
UserdefinedinputintheGitcommand
Creative Commons“Attribution-NonCommercial-NoDerivatives 4.0 International” license cbnd
v.2018.11.27
The words contained in this file might help you see if this file matches what you are looking for:
...Git cheat sheet cira software engineering group getting conguring whatwasithinking reviewinghistory undoingchanges is a freely available open source version control for linux windows and mac gitgetsit you yourcollaboratorsaren talwaysperfect browse inspecthowthelesintheproject togetgit visit https scm com downloads havechangedaswellaseraseyourmistakes checktheversionofyourgitinstallation log list history the currently checked out branch tags amorehuman readableversionof set display local conguration information config your current decorate full follow single le global user name sets username associated with commits blame addsuser loginformationaboutlechanges email want attached to diff changesbetweenapreviouscommit currentlestate color ui addsasplashofcolortogittomakeyourlifeeasier shows changes in between branches note thatthe blendsthedifferencesbetweenthetwover auto sions together make it easier compare if are not fan of system s default can core editor changetheeditor e g atom vim ...