2 Git - rciak/zz_42_shared_notes GitHub Wiki

Learning git

Git Commands in Workflows

Preparational step at 42 Vienna Computers

Install the program meld and link it to git as described here.

Remark: Many of the following commands can be followed by a list of files making them more selective ...

Adding changes more securely and more organized

  1. See the changes made since the last git add

    • git status
    • git difftool
  2. Preparing more organized or even atomic commits: Add only selected changes

    • git add -p
  3. Continue coding more / repeat 2. until commit is ready

  4. More secure commiting: See all the changes that have been added so far:

    • git difftool --staged
    • git commit

Branches: listing, creating, switching and merging

  • git branch
  • git branch new_branch
  • git checkout new_branch
    :
    :
  • git checkout main (or other branch in which we want to merge)
  • git merge new_branch

Using git as time machine to return to state of an old commit

  • git log --graph --all --oneline *or* git log --graph --decorate=short --all --oneline --color | less -R -X *or*git log --graph --decorate=short --all --oneline --color | less -R -X | head -17`

  • git checkout <commit ID>

  • git checkout main (if you want to return to the main branch afterwards)

Some other useful git commands

  • git ls-files

  • git revert and git revert --abort

  • git difftool <commit ID1> <commit ID2>

  • git stash and git stash pop

⚠️ **GitHub.com Fallback** ⚠️