Git¶
Git is a version control system for code projects.
Download (Debian)¶
apt install git
Initialize Git repository¶
git init
Add all changes as new commit¶
git add .
git commit -am "The commit message goes here"
Create a new branch¶
git checkout -b the_name_of_the_new_branch
Merge two branches¶
git merge name_of_the_brach_to_merge
List all branches (remote and local)¶
git branch -v -a
Switch to an branch¶
git switch name_of_the_branch_to_switch_to
Delete a branch¶
local:
git branch -d name_of_branch
remote
git push -d remote_name branch_name
When the branch was deleted in the remote by a third party you can remove the corresponding local remote branch by running:
git fetch -p
Undo git add¶
git reset
Discard local changes¶
git reset --hard HEAD
# Print all untracked files that can be deleted
git clean -n -d
# Delete all untracked files and directories
git clean -fd
Get url of remote¶
git remote get-url name_of_remote_probably_origin
Set url of remote¶
git remote set-url name_of_remote_probably_origin name_of_the_url
Set user name and email¶
git config user.name "<your name>"
git config user.email "<your mail>"
Shortcuts¶
Some of the git commands are also defined as shortcuts in the bashrc config of the debian-i3-pc-setup