Created: 2021-07-03 Sat 14:35
git-intro_Final-1.1.pdf
git-intro_review_by_expert
(send by email, modified three times)
sudo apt install git
In the following we will use the Command Line interface. Windows user can use
the git bash
software.
Who are you ?
git config --global user.name "USCTrobot" git config --global user.email USCTrobot@kit.edu
choose your editor (linux user)
git config --global core.editor nano
~/.gitconfig
From scratch :
$ cd my_awesome_project $ git init
this a created a .git
folder in your project, which will contains the history
of your modifications.
Start from someone else work
$ git clone https://gitlab.crans.org/plop/toto
git add
$ git add CONTRIBUTINGS.md
$
I did multiples modifications to a file
$ git add -p
Use a commited file: .gitignore
.
# useless to follow: *.[ao] *~ *.pyc *.pdf # full folder: auto/
~/.gitignore_global
(and use git config --global core.excludes_files ~/.gitignore_global
)
git status
git status On branch master Your branch is up to date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: CONTRIBUTINGS.md Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) README.md Untracked files: (use "git add <file>..." to include in what will be committed) LICENCE.md
Condense display : git status -s
git diff
git status
give only the global state of your repository. Git can also show
internal modifications:$ git diff
I did git add
and then git diff
and nothing shows up
git diff
only work on unstaged files by default (by comparing them with staged
and commited files). For change in the staged area (compare with commited area)$ git diff --staged
git commit
$ git commit # open a text editor for commit message.
Commit are build with:
5b05ec755a65ecda62e32d09ddc513a549b941f6
)All together your commit form a chained list.
faster : git commit -m "message direct"
git rm
git rm files_to_delete
git mv
$ mv old_name.txt new_name.txt $ git rm old_name.txt $ git add new_name.txt
make it easy:
git mv README.txt README
$ git log commit 5b05ec755a65ecda62e32d09ddc513a549b941f6 (HEAD -> master, origin/master) Author: Pierre-antoine Comby <comby@crans.org> Date: Thu Mar 7 22:39:47 2019 +0100 update avant partiel commit fbd4103b7dc1ca88b2ae084cc0d693db39f45dd8 Author: Pierre-antoine Comby <comby@crans.org> Date: Thu Mar 7 14:44:34 2019 +0100 sous optimal mais fonctionnel
lots of usefull files:
-p
show diff between commit.-2
limit to the last two commits--stat
--all
--graph
--oneline
--decorate
pro tip: git is –(A)ll –(G)raph –(O)neline –(D)ecorate
$ git commit -m "validation initiale" $ git add truc_oublie $ git commit --amend
I git add
something I did want to
git reset HEAD mon_fichier
-> proposed by git status
-> Revert the modification in your file.
$ git checkout -- mon_fichier
You lost FOREVER this modification.
master
) point to the last commit realized on this branch.
HEAD
point to the active branch. C’est actual state of your
repository (if you do not have any unstaged modifications).$ git branch testing # create a branch $ git checkout testing
I’m lazy …
$ git checkout -b testing $ git commit -m "testing something"
$ git checkout master $ git commit -m "mastering something"
$ git checkout master $ git merge hotfix Updating f42c576..3a0874c Fast-forward index.html | 2 ++ 1 file changed, 2 insertions(+)
$ git merge iss53 Auto-merging index.html CONFLICT (content): Merge conflict in index.html Automatic merge failed; fix conflicts and then commit the result.
what happen ?
$ git status On branch master You have unmerged paths. (fix conflicts and run "git commit") Unmerged paths: (use "git add <file>..." to mark resolution) both modified: index.html no changes added to commit (use "git add" and/or "git commit -a")
$ nano index.html <<<<<<< HEAD:index.html <div id="footer"> On branch master</div> ====== <div id="footer"> On branch iss53 </div> >>>>>>> iss53:index.html
git mergetool
for help.git add index.html
et git commit
pour conclure la fusion.$ git branch -d iss53
git branch -D
the more the merrier
$ git remote origin $ git remote -v origin git@git.scc.kit.edu:xyz/usct.git (fetch) origin git@git.scc.kit.edu:xyz/usct.git (push)
$ git remote add pb https://github.com/paulboone/ticgit $ git remote -v origin https://github.com/schacon/ticgit (fetch) origin https://github.com/schacon/ticgit (push) pb https://github.com/paulboone/ticgit (fetch) pb https://github.com/paulboone/ticgit (push)
$ git remote show origin
$ git fetch [remote-name]
For Get and merge
$ git pull
I made some awesome modification, I want to share it to others.
$ git push origin master
*
*
*
$ cd ~/.ssh $ ssh-keygen -b 4096 -t rsa => enter name for your key (ex GitlabKey) $ cat gitlab.pub
copy paste it in your gitlab account settings.
- your can now clone/pull/push via ssh.
- encryption of commit are also possible via GPG.
stash
git stash apply
git stash list
git stash show
.git
folder if you are not
sure of what you’re doing.