Repository for Ideas & Research
Open Source GIS, Hydrologic Modeling, Optimization
Tags: , ,


1   Create a new repository

# Enter the project directory
cd project

# Create the ignore list

# Create an empty repository
git init

# Stage project files
git add .gitignore *

# Commit
git commit -m 'Initial import'

2   Clone an existing repository

git clone user@server:path/to/project

3   Add a remote

git remote add remote_name remote_url

4   Pull

git pull remote_name branch_name

5   Pull individual files

Is it possible to pull just one file in Git?

git fetch {remote}
git checkout FETCH_HEAD -- {file}

6   Undo

How to undo last commit(s) in Git?

6.1   Local commit

git reset --soft HEAD^     # use --soft if you want to keep your changes
git reset --hard HEAD^     # use --hard if you don't care about keeping the changes you made

6.2   Public commit

git revert HEAD
git commit -m 'Revert'

7   Tag

git tag                                 # list tags
git tag -l pattern                      # list tags matching pattern
git tag -a v0.1 -m "annotated tag v0.1" # create an annotated tag
git show v0.1                           # show tag information

git tag v0.1-lw                         # create a lightweight tag

8   Show the origin URL

git config --get remote.origin.url

git remote show origin

9   Rename a branch

Rename a local and remote branch in git

# Rename your local branch.
# If you are on the branch you want to rename:
git branch -m new-name

#If you are on a different branch:
git branch -m old-name new-name

# Delete the old-name remote branch and push the new-name local branch.
git push origin :old-name new-name

# Reset the upstream branch for the new-name local branch. Switch to the branch and then:
git push origin -u new-name

10   Cache credentials

Git credential cache, why type password again and again

# timeout after 28,800 seconds (8 hours)
git config --global credential.helper 'cache --timeout 28800'

# forget
git credential-cache exit

# Windows
git config --global credential.helper wincred

11   References