Git
Git is a distributed version control system
Most operations you do with git is local.
Git stores snapshots of your work every time you commit, as opposed to a list of changes as many other VCS does.
One of the main features of git is branching allowing you to have many different local versions of your codebase.
And you can choose to only push a single branch to a remote repository
git init
To create a git repository simple use the git init command
terminal
Copy
$ git init
what git init does, is it adds the .git folder to your current location.
terminal
Copy
$ ls -a
./ ../ .git/
and that is all a git repository is, a folder containing a .git folder
git status
git status will tell you what files are being tracked, and if any of the files are in the staging area.
terminal
Copy
$ git status
On branch main
No commits yet
nothing to commit (create/copy files and use "git add" to track)
If we use the command touch test.txt, and then use git status again.
JS
Copy
$ git status
On branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.txt
nothing added to commit but untracked files present (use "git add" to track)
As one can see we now have an untracked file, and it even give us a helpful message.
We can use git add to track it!
git add
git add allow us to add untracked files or changed files to the staging area.
terminal
Copy
$ git add test.txt
After we use the command to add the test.txt to the staging area lets use git status again
terminal
Copy
$ git status
On branch main
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: test.txt
Aha, we can now see our file under 'changes to be commited'
you can use 'git add .' to add all changes and new files from the current directory and subdirectories.
or 'git add -A to add all changes, new files and deletions, from the entire git repository regardless of location.
git commit
git commit is used to commit any changes from the staging area
it's important to add a descriptive message to a commit with the -m flag
terminal
Copy
$ git commit -m 'added test.txt'
git push/pull
git push will push the current branch to it's remote origin if set
git pull will pull down changes from the upstream branch often origin/main
git clone
You can use git clone, to well clone/download a remote repository to your local machine
terminal
Copy
$ git clone <remote_url>