Quick reference for git use on your projects.
$ cd /Users/user/project/src
$ git init
These commands are nice because you can access them anywhere, even offline.
$ git help <verb>
$ git <verb> --help
$ man git-<verb>
$ git config --list --show-origin
$ git config --list
If not already done (as global config for example) setup your name and email.
$ git config --global user.name "Your Real Name"
$ git config --global user.email "you-email@@users.noreply.github.com"
If your start from an existing project clone it.
$ git clone git@github.com:jonatanmv/Git-Utils.git
or
$ git clone https://github.com/jonatanmv/Git-Utils local_directory
You can check your remotes info with git remote
. For example, when you clone a repository it will add automatically the origin remote. So git fetch origin
fetches any new work that has been pushed to that server since you cloned or fetched.
$ git remote -v
$ git remote show origin
And you add remotes like this:
$ git remote add origin git@github.com:jonatanmv/Git-Utils.git
$ git remote add paul https://github.com/paulboone/Git-Utils
Or change from ssh to https:
git remote set-url origin https://github.com/jonatanmv/Git-Utils.git
Create the repository on github website and push your repository from the command line:
git push -u origin master
So you will download lates changes on remotes with git fetch <remote>
. fetch only download info not the actual files. For that you will use pull (It will fetch and download changes).
$ git pull origin
$ git add *.c
$ git add LICENSE
$ git status
$ git commit -m 'initial project version'
You can easily create a .gitignore file this way:
$ cat .gitignore
__pycache__
*~
*.pyc
.DS_Store
.gitignore
logfiles/
Here another .ignorefile
# ignore all .a files
*.a
# but do track lib.a, even though you're ignoring .a files above
!lib.a
# only ignore the TODO file in the current directory, not subdir/TODO
/TODO
# ignore all files in any directory named build
build/
# ignore doc/notes.txt, but not doc/server/arch.txt
doc/*.txt
# ignore all .pdf files in the doc/ directory and any of its subdirectories
doc/**/*.pdf
$ git clone https://github.com/schacon/simplegit-progitx1x1x
$ git push
In case commands are blocked by email privacy then:
$ git config --global user.email "you-email@@users.noreply.github.com"
$ git commit --amend --reset-author