You are here

Git training and reference material

logo

Set user name and email for current repository

git config user.name "<userName>
git config user.email "<userEmail>"

Ignore files added to .gitignore that have been already committed

# Remove the files from the index:
git rm --cached <fileName>
# For a directory:
git rm -r --cached <directoryName>

Clone a project with submodules

# Cloning a project with submodules:
git clone <projectURL>
cd <projectDir>
git submodule init
git submodule update
# A more condensed way to do the same:
git clone --recurse-submodules <projectURL>

Push a modified submodule

cd <submodule>
git checkout -b <newBranch>
git push <remote> <newBranch>

Update a submodule to remote branch

cd <submodule>
git pull <remote> <branch>

Switch branch without committing

# Save current work:
git stash
# Switch to another branch and work...
# List if something has been saved:
git stash list
# Restore work in progress:
git stash apply

Display a branch graph

git log --graph --oneline --all

Delete a branch

Local branch:

git branch -d <branch>

Replace -d switch by -D switch to force deletion if the branch has not been merged.

Remote branch:

git push <remote> --delete <branch>

Copy a remote repository to another place

See this link.

On GitHub: How to request a review on a committed main branch?

git checkout --orphan full_review
git rm -r --cached *
git clean -fxd
git commit --allow-empty -m "Empty commit"
git branch empty
git merge main --allow-unrelated-histories
git push origin full_review
git push origin empty

Then, create a pull request for full_review against empty.

Flight rules for git

Source


clipart source