Git: Difference between revisions

From David's Wiki
No edit summary
Line 92: Line 92:


==Clean==
==Clean==
[https://www.atlassian.com/git/tutorials/undoing-changes/git-clean Atlassian Reference]
[https://www.atlassian.com/git/tutorials/undoing-changes/git-clean Atlassian Reference]<br>
Use <code>git clean</code> to delete untracked files.<br>
Use <code>git clean</code> to delete untracked files.<br>
Add <code>-x</code> to also delete gitignore'd files.
Add <code>-x</code> to also delete gitignore'd files.

Revision as of 15:01, 20 January 2020

Git is a popular version control system made by Linus Torvalds.

Installation

Windows

Download Git for Windows

Linux

sudo apt install git git-lfs

Basic Usage

# Clone or download a repository
git clone <url>

# Stage your changes
git add <my files>
# Or stage all files
# git add .

# Make a commit
git commit -m "My commit message"

# Push your changes to the repository
git push

# Pull the latest changes from the repository
# Equivalent to git fetch && git merge FETCH_HEAD
git pull

Branches

# Make a branch
git checkout -b my_feature

# Add and commit to this branch
git add .
git commit -m "My commit message"

# Push
git push --set-upstream origin my_feature

Pull Requests

Migrating Repositories

How to migrate repositories to another Git server

git clone --mirror <original_repo>
cd <repo>

# Run the following lines only if you're using lfs
git lfs fetch --all
git lfs push --all <new_repo>

git push --all <new_repo>

Changing Remote URL

Reference
You will need to change the remote url if it is changed on the server. E.g. if you change the project name.

git remote set-url origin <new-url>

gitignore

.gitignore is used to ignore certain files to make sure they do not get accidentally pushed to the remote git repo.
You can find a collection of .gitignore files on Github's gitignore repo.
Or you can create a custom .gitignore file at gitignore.io.

gitattributes

.gitattributes are used to give attributes to paths.
They can be used to assign programming languages to filenames.
They are also used to identify which files should be stored in the lfs.
Here is an example to store video and images in the lfs.

## Video
*.mp4 filter=lfs diff=lfs merge=lfs -text
*.mov filter=lfs diff=lfs merge=lfs -text
*.flv filter=lfs diff=lfs merge=lfs -text

## Pictures
*.png filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
*.jpeg filter=lfs diff=lfs merge=lfs -text

## Binary files
*.bin filter=lfs diff=lfs merge=lfs -text
*.7z filter=lfs diff=lfs merge=lfs -text

Clean

Atlassian Reference
Use git clean to delete untracked files.
Add -x to also delete gitignore'd files.

# Force delete any untracked files and directories
git clean -fd

Git Large File Storage (LFS)

Reference