- git init : to create new git repo
- git status:
- git add adds files
- git diff
- git commit
Git show HEAD
git checkout HEAD filename
File changes in filename discarded
git reset HEAD filename
This command resets the file in the staging area to be the same as the HEAD commit. It does not discard file changes from the working directory, it just removes them from the staging area.
git reset SHA
This command works by using the first 7 characters of the SHA of a previous commit.
git checkout HEAD filename: Discards changes in the working directory.
git reset HEAD filename: Unstages file changes from the staging area.
git reset SHA: go to a previous commit
add multiple files to staging area:
git add filename_1 filename_2
git branch: Lists all a Git project’s branches.
git branch branch_name: Creates a new branch.
git checkout branch_name: Used to switch from one branch to another.
git merge branch_name: Used to join file changes from one branch to another.
git branch -d branch_name: Deletes the branch specified.
The workflow for Git collaborations typically follows this order:
- Fetch and merge changes from the remote
- Create a branch to work on a new project feature
- Develop the feature on your branch and commit your work
- Fetch and merge from the remote again (in case new commits were made while you were working)
- Push your branch up to the remote for review
Steps 1 and 4 are a safeguard against merge conflicts, which occur when two branches contain file changes that cannot be merged with the
git merge command. Step 5 involves
git push, a command you will learn in the next exercise.
We also learned the following commands
git clone: Creates a local copy of a remote.
git remote -v: Lists a Git project’s remotes.
git fetch: Fetches work from the remote into the local copy.
git merge origin/master: Merges
origin/masterinto your local branch.
git push origin <branch_name>: Pushes a local branch to the