Software Development

Git cheat sheet

Here is my little cheat sheet for working with git at the command line.

Check the status of the current repository:

git status

This will return details of which files are modified and any files that are untracked, etc.

Add a file to the repository:

git add <filename>

You can also replace filename with a dot (.) to include all untracked files. Use git status before to find out what files are currently untracked.

Commit the changes to the local repository:

git commit -m "<commit message>"

This will only commit the changes as far as the local repository.

Send the changes back to the server:

git push origin master

origin is the name of the remote location of the repository. It is more-or-less, by convention, where you cloned your local repository from.

master is the name of the branch. By convention this is your default branch.

Revert a file to the version at the previous commit:

git checkout -f <filename>

Delete files from the repository

git rm <filename>

If you want to delete an entire directory you need to add the -r (recursive) flag.

git rm -r <folder-path>

You may also need to choose between keeping the files on the disk and removing them altogether. In which case you want either --cached, to remove them from the repository but keep them on disk, or -f to force the removal of the file from disk.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s