Git¶
Git is a version control system for tracking changes in computer files and coordinating work on those files among multiple people.
Note
VS Code has a built-in Git support. You can use it to manage your repositories without using the command line.
Most used commands¶
Get latest changes from remote repository:
git pull
Note
Use --rebase
flag to rebase local changes on top of remote changes.
Add new file to index:
git add <file>
Note
You can add all files in current directory with git add .
or git add -a
Danger
-f
flag is used to force all files to be added to the index also if they are ignored by .gitignore
file.
Commit changes:
git commit -a -m "Commit message"
Note
You can use git commit -a
to commit all changes in tracked files.
If you want to commit only a specific file, you can use git commit -a <file> -m "Commit message"
Other useful commands¶
Note
To leave the vim editor, type :q
and press enter.
Show status of tracked files:
git status
Show changes in tracked files:
git diff
Show changes/tracked/untracked of local files:
git status
Show commit history:
git log
git log options
You can also filter the log:
Command | Description |
---|---|
--author=<author> |
Show commits by author |
--grep=<string> |
Show commits with message containing string |
--since=<date> |
Show commits after date |
--until=<date> |
Show commits before date |
--oneline |
Show commits in one line |
--graph |
Show commits as a graph |
branch¶
Create new branch:
git branch <branch name>
Switch to branch:
git checkout <branch name>
Merge branch into main:
git checkout <main branch>
git merge <branch name>
staging¶
This is the area where you see tracked files that are not yet committed.
Init git & push to remote origin¶
git init
git add .
git commit -m "Initial commit"
git remote add origin <remote repository url>
git push -u origin master