Skip to content

gitAtAMin

holzkohlengrill edited this page Dec 15, 2023 · 8 revisions

Most important and essential git commands.

Init config (do only once)

git config --global user.name "Marcel"
git config --global user.email "marcel@tfp.invalid"

See also .gitconfig

Add existing Project to new repo

cd existing_folder
git init                    # Initialise git "env"
git remote add origin https://github.com/TeamFlowerPower/kb.wiki.git   # Add repo URL to remotes
git add .                   # Add all files
git commit                  # Commit files to repo
git push -u origin master   # Push and set upstream (-> `-u`)

Create new repo with empty project

git clone https://github.com/TeamFlowerPower/kb.wiki.git
cd kb.wiki

Basic workflow

git add contributors.txt        # optional
git commit -m 'Initial commit with contributors'
git push origin master

Staying up-to-date

Command Description
git log Show last commits (+metadata)
git log --name-status Show changed files and their status per commit
git whatchanged -p or git log -p Show textual diffs of last commit
git whatchanged Show changed files + commit messages
git diff Review changes before commit (show uncommitted changes)

Unpushed commits (rescure!)

Command Description
git reset --soft HEAD~1 Throws your last (local) commit away (make sure you're on HEAD)
git reset --hard HEAD~1 Throws your last (local) commit away and reverts all your local changes to the last commit (make sure you're on HEAD)
git commit --amend change your last unpushed commit
git add ./blah && git commit --amend --no-edit Include a file to your last commit (i.e. if you have committed only for one file but forgot another which matches you commit message); --no-edit does not open the editor for editing the commit message
Clone this wiki locally