Working with git
Contents
- 1 Interacting with a remote repository
- 1.1 Check out a repository:
- 1.2 Find out what changes were made to a remote repository:
- 1.3 Update from a repository, if there are no local uncommitted changes:
- 1.4 Update from a repository, if there are local changes:
- 1.5 Push to a repository:
- 1.6 Create a branch containing the current snapshop of the local repository, including all uncommitted changes, and switch to this branch
- 1.7 List all branches
- 1.8 Switch to a branch, if there are no uncommitted changes
- 2 Committing
- 3 Making local changes
- 3.1 Revert an uncommitted change to a file:
- 3.2 Add a file to the repository:
- 3.3 Remove a file from the repository:
- 3.4 Undo adding a file to the repository:
- 3.5 Undo removing a file from the repository, recreating the file manually:
- 3.6 Undo removing a file from the repository, resurrecting the file in the repository:
Interacting with a remote repository
This page describes solution to typical needs with git. If you are new to git, please read any of the fine tutorials to learn about the concepts that git offers, and how one would typically work with git.
Later, if you get stuck, or if you maneuvered yourself into a corner, you can come back here to find solutions to particular problems. That is, this page is not organised by "how do I do thing that are natural for git", but rather "how do I map things I need to do onto actions that are natural for git".
This page is split into three parts:
- Interacting with a remote repository (pull, push, merge)
- Local commits
- Working (adding/removing files, undoing changes)
Check out a repository:
git clone <remote-repo-url> <local-repo-name> git clone carpetgit@carpetcode.org:McLachlan McLachlan
Find out what changes were made to a remote repository:
???
Update from a repository, if there are no local uncommitted changes:
git pull
How to merge?
Update from a repository, if there are local changes:
Save all local changes:
git stash
Then update as described above. Re-apply all local changes:
git stash pop
If there are no conflicts, you are done. If there are conflicts, handle them, then:
git stash drop
since "stash pop" doesn't pop the stash if there are conflicts. "git stash list" shows all stashes. It is not possible to look at the content of a stash (???).
Push to a repository:
Ensure all remote changes have been pulled
git push
Create a branch containing the current snapshop of the local repository, including all uncommitted changes, and switch to this branch
should this maybe be split into two actions: creating a remote branch, and switching to this branch locally?
List all branches
git branch
??? This doesn't list new remote branches, does it?
Switch to a branch, if there are no uncommitted changes
git checkout <branch-name>
Committing
Commit a change:
git add <list-of-files-to-commit> git commit
Undo a commit that hasn't propagated yet, keeping all local changes:
??? (probably some variation of "git reset" and "git checkout")
Revert a commit that may have propagated already, keeping all the changes as local modifications:
???
Revert a commit, dropping all changes that it made:
??? (some variation of "git reset")
Making local changes
Revert an uncommitted change to a file:
git checkout -- <file>
Add a file to the repository:
Create file locally
git add <list-of-files-to-add>
Then commit.
Remove a file from the repository:
Delete file locally
git rm <list-of-files-that-were-removed>
(Is there a way to let git determine automatically which files were removed?) Then commit.
Undo adding a file to the repository:
Delete file locally
git reset HEAD <file>
Undo removing a file from the repository, recreating the file manually:
Create file locally
git reset HEAD <file>
Undo removing a file from the repository, resurrecting the file in the repository:
??? (probably a combination of "checkout" and "reset")