git cheat sheet
Staging area#
Unstage the change#
git reset HEAD <source>Restore file from repository#
git checkout HEAD <source>Remove file#
git rm <source>Move file#
git mv <source> <destination> Add changes in the working directory to the staging area#
git add .The
staging arealets you construct your next commit in a logical, structure fashion.
Moving files around and deleting them from the filesystem, without notifying Git, will cause you grief.
.gitignore#
Ignore all files that match this pattern#
*.<pattern-name>Ignore all files that aren't in the top-level directory#
*/*.<pattern-name>Despite any higher-level rules, don't ignore any files#
!/*.<pattern-name>Looking at the global .gitignore#
git config --global core.excludesfileCreate global .gitignore#
touch ~/.gitignore_globalSet global .gitignore#
git config --global core.excludesfile ~/.gitignore_globalSample .gitignore files#
https://github.com/github/gitignore
.gitignore lets you configure Git so that it ignores specific files or files that match a certain pattern.
!negates a matching rule.
Log & history#
Limiting results#
git log -<number>Compact view of the repository history#
git log --onelineGraphical view of the repository#
git log --graphCompact graphical view of the repository#
git log --graph --onelineViewing non-ancestral history#
git log --oneline --graph --allSummary of the commits#
git shortlogSearching git history#
Names#
Name that consists of one part;
git log --author=kaanf --onelineName that consists of two or more parts;
git log --author="Kaan Fırat" --onelineWords#
git log --grep=<word> --onelineSingle file#
git log --oneline <source>Directory#
git log --oneline <directory>This shows you all the changes that happened in that directory, but it’s not clear which files were changed.
Detailed information#
git log --oneline --stat <directory>Commits that deal with the term#
git log-S"<term>"Commits that deal with the term - (detailed)#
git log-S"<term>" -pCommits on other branches#
git log --all -S"<term>"Branching#
Create new branch#
git branch <branch-name>Checking current branch#
git branchSwitching to another branch#
git checkout <branch-name>Delete branch#
git branch -d <branch-name>Merging#
Fast forward merge commit#
git merge <branch-name> --no-ffCommits that are not in main branch#
git log <branch-name> --not <main-branch>Remote repository#
Change workstation branch (master -> main)#
git branch -M maingit push -u origin mainBasics#
Set up a Git repository#
git initAdd a remote repository to local#
git remote add origin <remote-url>