Workspace • Git Cheatsheet • NDP Software. Stash workspace index local repository upstream repository status Displays: <br>• paths that have differences between the index file and the current <code>HEAD</code> commit, <br>• paths that have differences between the workspace and the index file, and <br>• paths in the workspace that are not tracked by git. diff Displays the differences not added to the index. diff commit or branch View the changes you have in your workspace relative to the named <em>commit</em>.
Add file... or dir... Adds the current content of new or modified files to the index, thus staging that content for inclusion in the next commit. Add -u Adds the current content of modified (NOT NEW) files to the index. Rm file(s)... Remove a file from the workspace and the index. mv file(s)... Move file in the workspace and the index. commit -a -m 'msg' Commit all files changed since your last commit, except untracked files (ie. all files that are already listed in the index). Checkout files(s)... or dir reset HEAD file(s)... reset --hard. An asymmetry between git pull and push « Mark’s Blog. Although git is an excellent system, which has certainly changed my way of working for the better, occasionally one comes across an inconsistency that seems bizarre. In case you don’t want to read the whole of this post, the one sentence summary would be, “By default, git push origin will update branches on the destination with one with the same name on the source, instead of using the association defined by git branch --track, which git pull origin would use — the config option push.default can change this behaviour.”
However, for a more detailed explanation, read on… Suppose someone has told you that they’ve pushed a topic branch to GitHub that they’d like you to work on. Let’s say that you’ve set up a remote called github for that repository, and the branch there is called new-feature2. With a recent git (>= 1.6.1) you can just do git fetch and then: git checkout -t github/new-feature2 git checkout -t -b add-menu github/new-feature2 $ git pull github 1. 2. 2. 4. So how should you push? Git Book - Basic Branching and Merging. Let’s go through a simple example of branching and merging with a workflow that you might use in the real world.
You’ll follow these steps: Do work on a web site. Create a branch for a new story you’re working on. Do some work in that branch. At this stage, you’ll receive a call that another issue is critical and you need a hotfix. Revert back to your production branch. Basic Branching First, let’s say you’re working on your project and have a couple of commits already (see Figure 3-10). Figure 3-10. You’ve decided that you’re going to work on issue #53 in whatever issue-tracking system your company uses. . $ git checkout -b iss53 Switched to a new branch "iss53" This is shorthand for: $ git branch iss53 $ git checkout iss53 Figure 3-11 illustrates the result. Figure 3-11. You work on your web site and do some commits. . $ vim index.html $ git commit -a -m 'added a new footer [issue 53]' Figure 3-12. Now you get the call that there is an issue with the web site, and you need to fix it immediately.
List remote branches. Committed 13 Feb 2009 Sometimes you may need to figure out what branches exist on a remote repository so you can pull them down and check them out, merge them into your local branches, etc. If you’re using GitHub or gitweb to host your repository it’s usually easy to determine the branch names, but if you need to get them in general or for scripts it’s not exactly clear. UPDATE: The comments have enlightened me quite a bit…there seems to always be more than one way to skin a cat using Git.
The easiest way is just to use the git branch commands’ various options. -a shows all local and remote branches, while -r shows only remote branches. $ git branch * master $ git branch -a * master origin/1-2-stable origin/2-0-stable origin/2-1-stable origin/2-2-stable origin/3-0-unstable origin/HEAD origin/master $ git branch -r origin/1-2-stable origin/2-0-stable origin/2-1-stable origin/2-2-stable origin/3-0-unstable origin/HEAD origin/master.