This page is focused on providing and explaining the commands I most commonly use to deal with git via the terminal. I can only recommend everyone knowing at least the basic commands even if you use external tooling.
Even though external tools add an unnecessary amount of abstraction to your workplace and understanding, I can recommend them to use for visualization.
Basics
-
normal workflow: implement your changes → save file → review changes via diff view → stage files → commit files → publish the changes also to your remote
-
initialize your project
-
preparing a commit is called staging: it means you add files to the index that will be used for the next commit
-
TODO: undo operation of git add → git reset (???)
Info
Sometimes, git doesn’t track a new file yet … This also that
git commit -am "..."
doesn’t add it to the index. You have to explicitly add the folder or the file to the index.
- making a commit
- push your changes: often you not only work alone but, want to synchronize your local repository with a remote repository (e.g., Github) to enable collaboration
Helpers
output the current state of your git repository
this command gives you information about which files you have not versioned yet, changed or staged
-
git history
-
visualizing the current changes
Merging
- merge one branch into your current one
Stashing
Branching
Working with remote
- TODO: git clone
- TODO: git upstream einrichten
- pull changes: synchronize your local repository with incoming changes from the remote repository
-
be careful: merge conflicts can already happen here
-
no local changes and you want to pull the newest changes
-
you previously had the newest changes, but made some local progress after that; that could be file changes and even some commits; important: you didn’t change the files that had been updated by the remote repository (otherwise you will get merge conflicts)
-
you changed files that were also changed by the remote repository → merge conflicts!
After that, you can resolve the merge via your text editor and select the changes you want to keep. Then you can commit the merge.
-
Fixing mistakes
Advanced
- TODO: git reset hard and soft
Submodules
on your own …