blob: 993b413cebe637a93c9e6194a93ad027593d7d52 (
plain) (
tree)
|
|
<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
<meta charset='utf-8'>
<title>Work</title>
</head>
<body>
<a href="index.html">Git Index</a>
<h1>1. Work</h1>
<p id="init">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;
<pre>
$ git init
</pre>
<p id="status">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";</p>
<pre>
$ git status
</pre>
<p id="add">Add all files to start tracking them;</p>
<pre>
$ git add .
</pre>
<p>Run again git status, it should report that new files have been added;</p>
<pre>
$ git status
</pre>
<p id="commit">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;</p>
<pre>
$ git commit -m "initial commit"
</pre>
<h2 id="local">2.1. Local workflow</h2>
<p id="log">Check ~/.bashrc for glog alias, help to check branches and their commit history;</p>
<pre>
# Git log
glog () {
git log --stat --decorate
}
# Git graph log
gloga () {
git log --graph --abbrev-commit --decorate --date=relative --all
}
</pre>
<p id="ls-files">Mark all deleted to commit;</p>
<pre>
$ git ls-files --deleted -z | xargs -0 git rm
</pre>
<p id="rev-list">Query last commit that affected current file path</p>
<pre>
$ git rev-list -n 1 HEAD -- .
$ git show f000 path/to/file
$ git diff --name-status f000 path/to/file
</pre>
<p id="checkout">Undo a file to specific commit</p>
<pre>
$ git checkout f000^ -- path/to/file
</pre>
<p>Join multiple commits into single one;</p>
<pre>
$ git log --oneline
$ git rebase -i oldest_commit_to_rewrite
</pre>
<p id="reset">Undo last commit;</p>
<pre>
$ git reset --soft HEAD~1
</pre>
<h2 id="logdiff">2.2. Logs, diff commits</h2>
<p id="format-patch">Create patch files to target branch/tag/ref;</p>
<pre>
$ git format-patch --no-prefix software-v0.0.1
</pre>
<p>Same using diff command;</p>
<pre>
$ diff -u orig file > file.patch
</pre>
<h2 id="remote">2.3. Working with remotes</h2>
<p>Adding a new remote;</p>
<pre>
$ git remote add newremotename https://machine.example.org/repo.git
</pre>
<p>Update local branches removed on remote set automatically;</p>
<pre>
$ git config --global fetch.prune true
</pre>
<p>This will prune on fetch or you can keep it manually;</p>
<pre>
$ git remote prune origin
</pre>
<p id="fetch">Update all branches with remote;</p>
<pre>
$ git fetch --all
$ git pull --all
</pre>
<p>If you want to track all remotes run this line
and then the commands mentioned above;</p>
<pre>
$ for remote in `git branch -r`; do git branch --track ${remote#origin/} $remote; done
</pre>
<p>Future updates;</p>
<pre>
$ git fetch --all
$ git pull --all
</pre>
<p>When using gitolite as remote, check following documentation;</p>
<ul>
<li>Permission related problems check if correct
<a href="../../tools/gitolite.html#adminusers">user account</a>
exists on git server or is public readable.
</li>
<li>Repository related problems check if exists or
<a href="../../tools/gitolite.html#adminrep">create one</a>
user permissions.
</li>
<li>Local user account and configuration check correct
<a href="../../tools/openssh.html#sshid">ssh identities</a>,
and profile alias have been setup.
</li>
</ul>
<a href="index.html">Git Index</a>
<p>This is part of the Tribu System Documentation.
Copyright (C) 2020
Tribu Team.
See the file <a href="../../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
for copying conditions.</p>
</body>
</html>
|