How to use Git
- Create a remote repository
- Create a local repository
- Add files to the local repository
- push the local files to the remote repository
Create a remote repository
How to setup a git server is in a different page.
I’m going to concentrate on how to create a repository in a remote server which is already setup for the git.
Our goal is to create a remote repository for the projects makefiles. This has files that automate my build processes.
- Login to the remote server as the git user
- go to the root folder of your git repositories
- in my case it will be /home/git
- create a folder called makefiles.git
$mkdir makefiles.git
- change to the folder as
$cd makefiles.git
- initialize the repository inside the makefiles.git folder as
$git --bare init
Setup the local repository
If you are adding a folder which contains the files for your project then go that folder.
- Initialize git in the folder as
$git init
- Mark to add all the files to the git as
$git add *
- Add all the files by committing the add as
$git commit -a
Setting the remote server for the local repository
We need to setup the local repository with the information about the remote repository
- first clear any settings about the remote server as
$ git remote rm origin
- now add the remote server name as
$ git remote add origin ssh://git@jaya.homelinux.org/home/git/makefiles.git
- if you are ready, send all the files to the remote server as
$ git push -u origin master
After this command both the remote and the local repositories are identical. You can either choose to continue working
or delete the local repository and get a copy from the remote
Working with the project
You would want to have a copy of the entire repository which can be done as follows
$ git clone ssh://git@jaya.homelinux.org/home/git/makefiles.git
Git Branches
the branches that you create are local and then you can send those branches online by pushing the changes to the repository.
$git branch <branch_name>
will create a branch branch_name for you now we can make a branch active by checkingout that branch
$git checkout <branch_name>
make sure that the changes on master appear in your new branch as follows
$git rebase master
now you can push these changes to the remote branch as follows
$git push origin <branch_name>
Merge
This is when you are working with a different branch. say you are working with a branch br_9_22_2012 and you want to merge into master.
First switch to master
$git checkout master
now merge the br_9_22_2012 to the master as follows
$git merge br_9_22_2012
now commit this these changes to the source control
$git commit -a -m "merge message"
Once all the changes are merged to the master, now you can push these to the server as all these changes are local to the disk
$git push -u origin master