Branching is "Save as..."

Branches are like "Save as..." on a directory. Best of all:

  • Easily merge changes with the original (changes tracked and never applied twice)
  • No wasted space (common files only stored once)

Why branch? Consider the utility of "Save as..." for regular files: you tinker with multiple possibilities while keeping the original safe. Git enables this for directories, with the power to merge. (In practice, svn is like a single shared drive, where you can only revert to one backup).

To add new branch master

git checkout -b master

This wi...

Ignoring versioned files

Some files in a repository change often but are rarely committed. Usually, these are various local configuration files that are edited, but should never be committed upstream.

Git lets you ignore those files by assuming they are unchanged. This is done by running the following command:

git update-index --assume-unchanged path/to/file.txt

Once you mark a file like this, Git completely ignores any changes on it. It will never show up when running git status or git diff, nor will it ever be committed.

To make Git track the file again,...

fatal: Authentication failed for 'https://emgs@bitbucket/emgstars/stars.git/'

Description

When using TortoiseGit to push a commit, there is an error:

git did not exit cleanly (exit code 128)

Using the console to push:

git push -u bitstars masters

and after entering the password, there is an error:

fatal: Authentication failed for 'https://emgs@bitbucket/emgstars/stars.git/'

Resolution

In the dialog of TortoiseGit for push, enter in Arbitrary URL:

https://<bitbucket username>:<bitbucket password>@bitbucket.org/emgsstars/stars.git

and then push.

TortoiseGit Makes Git Easy

Instructions

  1. Install TortoiseGit
  2. Install Git For Windows

Using SSH with TortoiseGit

ref: https://confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Git

  1. Follow the guide from STEP 1 to STEP 7
  2. ~/ means home directory, in MS Wins, it is located in C:\Documents and Settings\New user.ssh
  3. The directory ~/.ssh contains the key files, after creating the public and private keys, place the files here
  4. Create the ssh config file to set the key to use for bitbucket (STEP 4). ~/.ssh/co...

Staging and Committing

A separate staging step in git is in line with the philosophy of getting out of the way until you need to deal with source control. You can continue to make changes to your working directory, and then at the point you want to interact with source control, git allows you to record your changes in small commits that record exactly what you did.

For example, suppose you edited three files (a.rb, b.rb, and c.rb). Now you want to commit all the changes, but you want the changes in a.rb and b.rb to be a single commit, while the changes to c.rb ar...

List added files which are not yet commited

git diff --cached --name-only --diff-filter=A 

will list all the files added since HEAD which don't exist in HEAD.

--name-only it'll list all the files changed in the index relative to HEAD
--name-status get the status symbol too
--diff-filter specify which set of files you want to show ('A'for newly added files, -M to turn on move detection, -C for copy detection)

Alternative

git status

Making Changes and Push

Every project needs a README file. Your README appears on the project Overview page and introduces your project.

echo "# This is my README" >> README.md
git add README.md
git commit -m "First commit. Adding a README."
git push -u bitbutket master

Create local repository and push to remote

Create Local Repository

  1. Download GitHub for Windows or use something similar, which includes a shell
  2. Launch Git Shell
  3. In the shell, navigate to the directory with cd
  4. git init to create a local repository

Alternatively, we can clone from a remote repository: git clone https://user@bitbucket.org/team-or-user-name/myproject.git folder_name

Add All Files and Directories to Git

  1. After git init, do
  2. git add .
  3. List the added files which are not yet comm...