This page assumes you have SSH access to your server and are comfortable with working on the command line.
Use git status. Sample output below:
$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # deleted: README # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # foo # modules/rescue nothing added to commit but untracked files present (use "git add" to track)
This says that you've locally deleted README, locally created foo and modules/rescue.
Use git stash. This will save any local changes and revert your client to a clean state. Start by taking a look at what you have:
$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: LICENSE # new file: foo.php # # Changed but not updated: # (use "git add/rm <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # deleted: README #
You've modified LICENSE, created foo.php and deleted README. Now we run "git stash":
$ git stash Saved working directory and index state "WIP on master: 0be38d1 Workaround to make G3 work with Turkish locale. Thanks to katpatuka for providing the fix." HEAD is now at 0be38d1 Workaround to make G3 work with Turkish locale. (To restore them type "git stash apply")
Note that it tells you the details of the most recent committed change. If we check now with git status:
$ git status # On branch master nothing to commit (working directory clean)
The working directory is clean. To get your changes back, run git stash pop
$ git stash pop Removing README # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: foo.php # # Changed but not updated: # (use "git add/rm <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: LICENSE # deleted: README # Dropped refs/stash@{0} (d75243798d7d89ef0fc4533f451832113c4293c6)
Now your changes are back again.
If you've committed changes to your local repo that you want to delete, you can use git rebase -i to find and remove them. git rebase -i HEAD~50 will give you an interactive editor with a summary of the last 50 changes. Find the lines that you no longer want and delete them and those changes will go away. If you accidentally delete changes from the core code that's no problem, they'll come back on your next git pull.
If you want to tell the differences between what you have in your private repo and what's in the upstream gallery3 repo, you can do git diff origin master and you'll see a comparison between what's in your repo and what's in the upstream repo.
Tracking a remote branch is easy. Just use git checkout -b <local branch name> --track <remote branch name>
Here are some quick edits to make your git environment a bit more personal. To make the changes just for a single git repo edit the .git/config file in your repo. To make the changes globally for you edit $HOME/.gitconfig.
To colorize the output of git, edit .git/config and add these line:
[color] diff = auto status = auto branch = auto
That will colorize the output of those git commands.
To shortcut your git commands you just need to alias them, here's how. Edit .git/config and add:
[alias] br = branch ci = commit co = checkout d = diff -w lg = log -p st = status sta = stash up = pull who = shortlog -s --
NOTE: This is just an example, customize your git config anyway you like for your usage.
If you work with git, you've probably had that nagging sensation of not knowing what branch you are on. Worry no longer!
Edit $HOME/.bashrc and add the following, making changes as necessary for your environment:
export PS1="\\w:\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)\$ "
This will change your prompt to display not only your working directory but also your current git branch, if you have one. Pretty nifty!
Example:
# ~/code/web:beta_directory$ git checkout master # Switched to branch "master" # ~/code/web:master$ git checkout beta_directory # Switched to branch "beta_directory" # ~/code/web:beta_directory$
NOTE: This works for Ubuntu and possibly other flavors of Unix.
Edit $HOME/.bashrc and add the following, making changes as necessary for your environment:
get_git_branch() { echo `git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* (.*)/1/'` } alias gpull='git pull origin `get_git_branch`' alias gpush='git push origin `get_git_branch`'
| The Git Community Book - An excellent resource for help learn Git as quickly and easily as possible.