You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
git clone git://github.com/schacon/grit.git 'name of local folder to reside in'
You can use a number of different protocols: git, http(s), etc.
Recording Changes to the Repository
Files can either be tracked or untracked
tracked files are files that were present in the last snapshot
these files can be unmodified, modified or staged
untracked files are everything else
Checking status of your files
To check status:
git status
Tracking new files
To start tracking an untracked file:
git add <fileToTrack/directory>
Staging modified files
git add is also used to stage modified files
if you stage a file, modify the same file, and then run git status
you will see the file mentioned twice. Once mentioning the staged
file to be committed and once for changes that have been made but
not staged. You must git add the file again to stage the latest
changes.
Ignoring files
Create a .gitignore file in the project:
# a comment - this is ignored# no .a files*.a
# but do track lib.a, even though you're ignoring .a files above!lib.a
# only ignore the root TODO file, not subdir/TODO
/TODO
# ignore all files in the build/ directory
build/
# ignore doc/notes.txt, but not doc/server/arch.txt
doc/*.txt
# ignore all .t
Viewing your staged and unstaged changes
To shows exact lines added and removed for a file that has been
changed but not staged:
git diff
To show changes that you have staged:
git diff --staged
Committing Your Changes
Only staged files are committed:
git commit
the -m flag allows you to add a commit message inline
the -a flag allows you to skip the staging area
Removing files
To remove a file from git:
git rm
To remove a file from the staging area:
git rm --staged <fileToRemove>
You can pass files, directories and file-glob pattern to git rm
Moving files
git does not explicitly track file movement
You can rename a file as follows:
git mv fileFrom fileTo
Viewing the Commit History
default command is:
git log
to show diff for each change use a -p option
to limit to the last x commits use -{x} were x is a number
remote repositories are repositories that are hosted on some network
Showing Your Remotes
to show remote servers (-v flag shows URL associated with that server):
git remote
one repository can have more than one remote in which case git
remote will list them all
Adding Remote Repositories
To explicitly add a remote repository:
git remote add <shortname><url>
after running above you can reference the repository by using
short-name instead of the url
Fetching and Pulling from Your Remotes
To get data from remote:
git fetch <remoteName>
The above will pull all data from the remote since you last fetched
the data or since you cloned the repository
It will not merge the changes
If you want to fetch the data and have it automatically merged run:
git pull
Pushing to Your Remote
To push your changes upstream use:
git push <remoteName><branchName>
For example:
git push origin master
The above will only work if no one else had pushed their changes
after you last did a fetch.
Inspecting a Remote
To get useful information about a remote:
git remote show origin
Removing and Renaming Remotes
To rename a remote’s shortname:
git remote rename
This will change the remote branch name as well
To remove a reference:
git remote rm <shortName>
Tagging
Git has the ability to tag specific point in history as being
important
Listing tags
to list tags:
git tag
you can filter tags like so:
git tag -l 'step-1*'
Creating Tags
Two different types:
Lightweight - Like a branch that doesn’t change. Basically a
pointer to a specific commit
Annotated - Stored as full objects in Git database. They’re
checksummed, contain the tagger name, email and date, have a
tagging message, and can be signed and verified with GNU privacy
guard
Annotated Tags
To create a tag:
git tag -a v1.4 -m 'my version 1.4'
the -a flag will create a tag and the -m is for an inline comment
To see tag info:
git show v1.4
Lightweight Tags
Nothing more than a commit checksum stored in a file
Run git tag without any flags – just specify name of tag:
git tag v1.4-lw
Tagging Later
You can tag a specific commit even if you moved past it by
specifying the checksum or part of the checksum:
git tag -a v1.5 -m 'my version 1.5' 9fceb02
Sharing Tags
by default the git push command does not transfer tags to remote
server