Git is very easy to use and very useful to keep information in text or other formats. To start using just go to a directory where you will test git, add some files and;
$ git init
This initiates git directory and configuration files for this repository, you can see new directory ".git/". The next command says the status of your working directory, since no files have been added it will report "untracked files";
$ git status
Add all files to start tracking them;
$ git add .
Run again git status, it should report that new files have been added;
$ git status
If you change any file it will report that the file have been changed at this moment, new changes can be added to current state of the files for the next commit. To commit;
$ git commit -m "initial commit"
Check ~/.bashrc for glog alias, help to check branches and their commit history;
# Git log glog () { git log --stat --decorate } # Git graph log gloga () { git log --graph --abbrev-commit --decorate --date=relative --all }
Mark all deleted to commit;
$ git ls-files --deleted -z | xargs -0 git rm
Query last commit that affected current file path
$ git rev-list -n 1 HEAD -- . $ git show f000 path/to/file $ git diff --name-status f000 path/to/file
Undo a file to specific commit
$ git checkout f000^ -- path/to/file
Join multiple commits into single one;
$ git log --oneline $ git rebase -i oldest_commit_to_rewrite
Undo last commit;
$ git reset --soft HEAD~1
Create patch files to target branch/tag/ref;
$ git format-patch --no-prefix software-v0.0.1
Same using diff command;
$ diff -u orig file > file.patch
Adding a new remote;
$ git remote add newremotename https://machine.example.org/repo.git
Update local branches removed on remote set automatically;
$ git config --global fetch.prune true
This will prune on fetch or you can keep it manually;
$ git remote prune origin
Update all branches with remote;
$ git fetch --all $ git pull --all
If you want to track all remotes run this line and then the commands mentioned above;
$ for remote in `git branch -r`; do git branch --track ${remote#origin/} $remote; done
Future updates;
$ git fetch --all $ git pull --all
When using gitolite as remote, check following documentation;
This is part of the Hive System Documentation. Copyright (C) 2019 Hive Team. See the file Gnu Free Documentation License for copying conditions.