Git Learning
Learning from Codecadamy: https://www.codecademy.com/learn/learn-git
Use Git commands to help keep track of changes made to a project:
git init
creates a new Git repositorygit status
inspects the contents of the working directory and staging areagit add
adds files from the working directory to the staging areagit diff
shows the difference between the working directory and the staging areagit commit
permanently stores file changes from the staging area in the repositorygit log
shows a list of all previous commitsgit checkout HEAD filename
: Discards changes in the working directory.git reset HEAD filename
: Unstages file changes in the staging area.git reset SHA
: Can be used to reset to a previous commit in your commit history.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.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/master into your local branch.git push origin <branch_name>
: Pushes a local branch to the origin remote.
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
To deploy a website:
//initialize a Git repository
git init
//In the example above, https://github.com/your-user-name/your-user-name.github.io.git is the remote URL that refers to the repository you created on GitHub earlier.
git remote add origin https://github.com/your-user-name/your-user-name.github.io.git
//Confirm that the remote was succesfully added
git remote -v
//Add all of your site's content to the Git staging area
git add .
//Save your changes using Git's commit command and the following commit message:
git commit -m "Save my work"
//push the contents of your site up to your repo
git push -u origin master