Git adding a new remote branch – detailed but simple example

Aug 28, 2012 by

Initial checkout (to ~/branchtest folder) since it was not specified


apollo:~max$ git clone git@bitbucket.org:inteist/branchtest.git

Let’s create a file named “master.txt”


apollo:~max$ echo This is master branch > master.txt

Now let’s add the file to track changes


apollo:branchtest max$ git add .
apollo:branchtest max$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#  new file:   master.txt

Now let’s push the file to the master branch (until now there were no refs). The “-u” switch adds upstream tracking
apollo:branchtest max$ git push -u origin master

Now let’s create a new branch and name it “new”. The “-b” switch makes us immediately switch to the “new” branch


apollo:branchtest max$ git checkout -b new
Switched to a new branch 'new'

Make sure we are on the “new” branch. Indeed we are.


apollo:branchtest max$ git status
# On branch new
nothing to commit (working directory clean)

Let’s add a file “new.txt”


apollo:branchtest max$ echo New addition > new.txt

It’s on the file system.


apollo:branchtest max$ ls
master.txt  new.txt

But is untracked by Git just yet


apollo:branchtest max$ git status
# On branch new
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#  new.txt
nothing added to commit but untracked files present (use "git add" to track)

Let’s add the file to be tracked


apollo:branchtest max$ git add .
apollo:branchtest max$ git commit -m "Adding the new file while on the new branch"
[new 67f764e] Adding the new file while on the new branch
 1 file changed, 1 insertion(+)
 create mode 100644 new.txt

Let’s switch back to “master” branch. The “new.txt” is not there. It is tracked under the new branch.


apollo:branchtest max$ git checkout master
Switched to branch 'master'
apollo:branchtest max$ ls
master.txt

Let’s switch back to the “new” branch


apollo:branchtest max$ git checkout new
Switched to branch 'new'
apollo:branchtest max$ ls
master.txt  new.txt

Now with the “master” branch pushed and the the “new” branch created locally but not pushed to the central repository, let’s clone the repository to a different folder.


apollo:max$ git clone git@bitbucket.org:inteist/branchtest.git branchtestNEW
Cloning into 'branchtestNEW'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.

We checked out the “master” branch, which has the “master.txt” as expected


$ cd branchtestNEW/
$ ls
master.txt

Let’s see if the “new” branch is present:


apollo:branchtestNEW max$ git checkout new
error: pathspec 'new' did not match any file(s) known to git.

Nop, it is not, of course, since we did not push it yet.

Now let’s push the the “new” local branch to the remote repository. Just to make a case, I will name it “newremote” on the remote.
This is not required. If the second parameter is omitted, then the local and remote names are the same.
We are going to have the “-u” switch so it is tracked in the upstream


apollo:branchtest max$ git push -u origin new:newremote
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 305 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: bb/acl: inteist is allowed. accepted payload.
To ssh://git@bitbucket.org/inteist/branchtest.git
 * [new branch]      new -> newremote
Branch new set up to track remote branch newremote from origin.

Let’s clone the repository to yet another folder.


apollo:~ max$ git clone git@bitbucket.org:inteist/branchtest.git branchtestNEWREMOTE
Cloning into 'branchtestNEWREMOTE'...
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), done.

Let’s see if there is the “new” branch now.


apollo:~ max$ cd branchtestNEWREMOTE/
apollo:branchtestNEWREMOTE max$ git checkout new
error: pathspec 'new' did not match any file(s) known to git.

Surprise? No. There is no “new” branch of course because we named it “newremote” on the remote and this is how it was checked out.

Was it?


apollo:branchtestNEWREMOTE max$ git checkout newremote
Branch newremote set up to track remote branch newremote from origin.
Switched to a new branch 'newremote'

Yes, it was :)

Let’s see what’s there:


apollo:branchtestNEWREMOTE max$ ls
master.txt  new.txt

And what about the “master” branch?


apollo:branchtestNEWREMOTE max$ git checkout master
Switched to branch 'master'
apollo:branchtestNEWREMOTE max$ ls
master.txt

Surely enough there is only what was tracked under the “master” branch

read more

Android file transfer stooped recognizing Galaxy Nexus on OS X

Aug 18, 2012 by

If you connect your Android Galaxy Nexus or any other Android phone to your OS X computer and the Android File Transfer app is not opening automatically or even if you open it manually, you get a message saying that there is no device connected. You simply need to turn off USB debugging.

While your Android phone is in USB debugging mode (this may not apply to all the phones but it certainly applies to Galaxy Nexus), android file transfer does not recognize it. Once you turn off the USB debugging mode, android file transfer should start recognizing the device once again.

read more

Share This

How to upgrade Eclipse Indigo to Eclipse Juno 4.2

Aug 10, 2012 by

It is possible to update Eclipse Indigo to the new Eclipse Juno while preserving your settings and (well, hopefully) everything else. Note that some plugins may not support the new Juno release yet, so consult your specific plugins release notes and updates to check this. Also make sure you make a backup of your Eclipse installation – just zip/tar the whole folder and if something goes wrong you should be able to just unzip/untar it back to its original location like nothing happened.

Add new sites to my “Available Software Sites” (Help -> Install New Software -> Available Software Sites)

http://download.eclipse.org/releases/juno
http://download.eclipse.org/tools/cdt/releases/juno

 

 

Then just initiate an update (help -> install updates).

After the update

http://download.eclipse.org/eclipse/updates/4.2

 had been added

http://download.eclipse.org/eclipse/updates/3.7

 had been disabled

http://download.eclipse.org/tools/cdt/releases/indigo

 had been disabled

read more

Related Posts

Share This

PHPStorm change default open in a new frame

Jul 10, 2012 by

When you (re)open a project in PHPStorm, it will ask you whether you want to open it in a new window or current. If you choose new window it will open another instance of PHPStorm and open there your project, if you choose otherwise it will replace the curent workspace with the new project. There is also a checkbox saying don’t ask me again and then this will be the usual setting from now on. Now what if you did something and then you regret. It took me some time to find out how to change this. Here it is. It’s quite simple actually and I would probably found it faster if I didn’t google for it but just would use some common sense and find it myself (which I eventually had to reserve to since googling did not help)

It’s basically Settings->General->Confirm window to open project in

read more

Java code to work with MillennialMedia, SMAATO and NexAge web advertising APIs

Dec 18, 2010 by

I wrote yesterday about my (mostly) negative experience working with these companies, but some of you might give it a try and maybe your results will be much better or maybe things have actually improved lately. In any case, the code here should get you up to speed covering most of the dirty work of working with these companies’ APIs.

I will post 4 classes here:

  • AdGrabber -  main abstract class to give all other specific grabbers structure and save some repeating code
  • MillenialAdGrabber - MillennialMedia specific grabber
  • NexAgeAdGrabber - right, NexAge specific grabber
  • SomaAdGrabber - the SMAATO ad grabber. Their ad platform is dubbed SOMA, hence the name

If you are using this code, please give an attribution when applicable with a link to this post.

read more

Android – Can’t find my ADB

Dec 6, 2010 by

Just installed the new Android SDK – 2.3 and wondering where’s “ADB”? Don’t worry it’s there.

In there recent release of the Android 2.3 codenamed “Gingerbread” the SDK’s directory was a little restructured. In particular the ADB (Android debug bridge) the tool that is used to communicate with the Android emulator instances and connected device has been moved. Previously you could find it in the

path_to_your_Android_SDK_installation/tools

folder.

But since the Android 2.3 (or API 9) the /tools folder was renamed to /platform-tools folder, so if you are wondering why suddenly your >adb command does not work – this is the reason and updating the PATH should fix it.

read more

Share This