How to use Git Flashcards
What is Git
Git is a version control system.
Git helps you keep track of code changes.
Git is used to collaborate on code.
Check what version of Git you are using
git –version
What does Git do
-Manage projects with Repositories
-Clone a project to work on a local copy
-Control and track changes with Staging and Committing
-Branch and Merge to allow for work on different parts and versions of a project
-Pull the latest version of the project to a local copy
-Push local updates to the main project
How do you work with Git
-Initialize Git on a folder, making it a Repository
- Git now creates a hidden folder to keep track of changes in that folder
When a file is changed, added or deleted, it is considered modified
-You select the modified files you want to Stage
-The Staged files are Committed, which prompts Git to store a permanent snapshot of the files
-Git allows you to see the full history of every commit.
-You can revert back to any previous commit.
-Git does not store a separate copy of every file in every commit, but keeps track of changes made in each commit!
Why do you use Git?
-Over 70% of developers use Git!
Developers can work together from anywhere in the world.
- Developers can see the full history of the project.
- Developers can revert to earlier versions of a project.
Creating Git Folder
mkdir myproject
cd myproject
Initialize Git
git init
Initialized empty Git repository in /Users/user/myproject/.git/
Git Adding New Files
git status
On branch master
No commits yet
Untracked files:
(use “git add …” to include in what will be committed)
index.html
nothing added to commit but untracked files present (use “git add
When to do a Git Staging Environment
As you are working, you may be adding, editing and removing files. But whenever you hit a milestone or finish a part of the work, you should add the files to a Staging Environment.
What is a staged file
Staged files are files that are ready to be committed to the repository you are working on.
Add file to the Staging Environment
git add index.html
How to check if a file is staged
git status
How to add all files to be staged
git add –all
Shortcut: git add -A
What is git commit
Adding commits keep track of our progress and changes as we work. Git considers each commit change point or “save point”. It is a point in the project you can go back to if you find a bug, or want to make a change.
How to do git commit?
When we commit, we should always include a message.
Code
git commit -m “First release of Hello World!”
[master (root-commit) 221ec6e] First release of Hello World!
3 files changed, 26 insertions(+)
create mode 100644 README.md
create mode 100644 bluestyle.css
create mode 100644 index.html
Why add a git commit message?
By adding clear messages to each commit, it is easy for yourself (and others) to see what has changed and when.
Git Push
git push <folderuwannaupload> main</folderuwannaupload>
make sure you cd .. so your not in the folder you wanna upload
How to view a history of commits
To view the history of commits for a repository
Git Commit without Stage
git status –short
then
git commit -a -m “message”
How to get Git Help
git command -help
See all the available options for the specific command
or
git help –all - See all possible commands
What is a Git Branch
is a new/separate version of the main repository.
How do you create a new branch
git branch hello-world-images
(Now we created a new branch called “hello-world-images”)
How do you check you created the branch
git branch
hello-world-images
* master
(We can see the new branch with the name “hello-world-images”, but the * beside master specifies that we are currently on that branch.)
What is Checkout
checkout is the command used to check out a branch. Moving us from the current branch, to the one specified at the end of the command:
How do you move to the branch you want
git checkout hello-world-images
Switched to branch ‘hello-world-images’
check the status of the current branch:
git status
How to add your changes
git commit -m “Added image to Hello World”
How to merge branches
- Make sure you are on the branch you want to merge to be on
-git add –all
git commit -m “added new image”
Move to the master branch
git checkout master
& merge
git merge hello-world-images
Git Ignore
https://www.freecodecamp.org/news/gitignore-file-how-to-ignore-files-and-folders-in-git/#create
requirments.txt
pip freeze > requirements.txt