Version Control
11.13 Github
3 Parts of Version Control
- Working Directory: This is the folder where you store your files (e.g.,
C:\Home\hw1
) - Staging Area: Every time you make changes to your files, you need to stage the files. This tells git that these files are ready
- Repository: Every working directory that uses git for version control will have a
.git
folder, which records info about each version of the working directory.
Basic git commands:
git --version
- Check version of git
git config --global user.name "John Doe"
git config --global user.email "johndoe@example.com"
- Configure git to recognize you
git config --global user.name
git config --global user.email
- Confirm that user name/e-mail are configured
git init
touch readme.md
git add readme.md
git commit -m "added readme file"
- Initialize new repository
- If you are at the file path
C:\Home\hw1
,git init
will initialize the repository in thehw1
folder - An invisible
.git
folder will be created in thehw1
folder to track files. If you are at the file path
C:\Home
and have not created thehw1
folder, then you can typegit init hw1
, which will create thehw1
folder and initialize the repo.- The code above did the following:
git init
: initialize repositorytouch readme.md
: added a blank readme Markdown filegit add readme.md
: staged readme.md (this tells git that you are ready to commit this file to the repo)git commit -m "added readme file"
: committed changed to the repo (-m
allows us to add a message)
- If you are at the file path
git diff
- Check differences between in the staging area and working directory.
- Output: difference between each file that has changed since you last staged files (
git add
) - If you have staged all files, this command will output nothing, since nothing is different between your working directory and staging area.
git diff --staged
- Check the differences between staging area and repository.
git log
- See list of commits.
git reset file1.md
- Suppose
file1.md
was staged, but I want to remove it from the staging area.- Now,
file1.md
will be untracked.
- Now,
git remote add origin https://github.com/<username>/<repo-name>.git
git push -u origin master
- Create a new repository in Github. Link your local working directory with the Github repo with these commands.
git remote add
: sends commits to the locationorigin
- We associated
origin
as a shortcut for the Github repohttps://github.com/<username>/<repo-name>.git
. git push -u origin master
- Send
master
branch to remote repo calledorigin
- Option
-u
allows us to usegit push
as a shortcut forgit push origin master
in the future
- Send