Git: Creating a Remote Branch (and track it locally)

Required steps to create and track locally a remote branch with git:

# Create new remote branch
git push origin origin:refs/heads/new_branch_name
 
# Make sure everything is updated
git fetch origin
 
# Check your branch has been created
git branch -r
 
# Track a remote branch
git branch --track new_branch_name origin/new_branch_name
 
# Checkout remote branch
git checkout new_branch_name
Advertisements
Git: Creating a Remote Branch (and track it locally)

Git: Undo commit

Sometimes, when the caffeine no longer works, you can make a mistake on a commit. Either you have second thoughts about your commit message, you just forgot to track new project files, or whatever the reasons are you can always undo your last commit (as long you don’t push it to origin repository):

$ git reset --soft HEAD^
Git: Undo commit

Git: Adding a Ruby on Rails Project to Git

Here’s how to add a recently created Ruby on Rails project to git:

1. Create your new project:

$ rails -d mysql project_name

2. Create some .gitignore empty files so you save the entire structure of your project (git doesn’t include empty folders):

$ touch db/.gitignore lib/.gitignore log/.gitignore tmp/.gitignore vendor/.gitignore

3. Create a new .gitignore file in the root directory of your project with the following content:

log/**/*
tmp/**/*
db/schema.rb

Note: If you are using sqlite add db/*.sqlite3 to .gitignore so you do not have the database into the repository (you can db:migrate it whenever you need it). Thanks for your reply Piku.

4. Initialize local repository:

$ git init

5. Add the project files and make que initial import:

$ git add .
$ git commit -a -m "* Initial import"

6. Finally if you have a gitosis server you can add it with the following commands:

$ git remote add origin git@YOUR_SERVER_NAME:project_name.git
$ git push origin master

That’s it, your project sources are now managed by git.

Happy hacking!

Git: Adding a Ruby on Rails Project to Git