Basics Flashcards
Create a new Git repository.
git init
Inspect the contents of the working directory and staging area.
git status
Add some files from the working directory to the staging area.
git add FILENAME1 FILENAME2
Show the difference between the working directory and the staging area.
git diff FILENAME1
Permanently store file changes from the staging area in the repository.
git commit -m “msg to save with the commit”
Show a list of all previous commits.
git log
See the HEAD commit.
git show HEAD
The output of this command will display everything the git log command displays for the HEAD commit, plus all the file changes that were committed.
Restore the file in your working directory to look exactly as it did when you last made a commit.
Name the shortcut of the command.
git checkout HEAD FILENAME1
Shortcut:
git checkout – filename
Reset (unstage) the file in the staging area to be the same as the HEAD commit.
git reset HEAD FILENAME1
It does not discard file changes from the working directory, it just removes them from the staging area.
Rewind to the part before the wrong turn. Set HEAD to the state of the previous commit.
git reset -commit_SHA-
-commit_SHA-: first 7 characters of the SHA of a previous commit. E.g.
git reset 5d69206
Add every file in the working directory to the staging area, instead of adding each file individually.
git add .
It is faster than specifying each file individually, but it’s easy to accidentally add files you don’t want there.
Identify on which branch you are working
git branch
Create a new branch.
Switch to the new branch.
git branch NEWBRANCH
git checkout NEWBRANCH
Merge the new branch into master branch.
First need to switch back to the master.
git checkout master
git merge NEWBRANCH
After the branch has been integrated into the master, it has served its purpose and can be deleted. Delete the branch.
git branch -d NEWBRANCH
If the branch was never merged into master we need the -D option.