about summary refs log tree commit diff stats
path: root/dev/git/work.html
blob: b72cfaef693d114f57dfa4ce24ace54341db5fad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!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 LeetIO System Documentation.
    Copyright (C) 2021
    LeetIO Team.
    See the file <a href="../../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
    for copying conditions.</p>
</body>
</html>