Git: Working on many different branches/projects within one file directory
Git is a distributed revision control system initially developed in 2005 by Linus Torvalds for Linux Kernel development. It is a different source code mangement system than the others. A Git working directory is a full-fledged repository with complete history and full version tracking capabilities, which means you can still do things such as view log history and commit changes even without a network access to the central repository where you got your local working copy.
git clone (remote repository url)
Get a clone of the remote repository.
git checkout -b testBranch origin/master
Checkout a branch off the origin/master.
git checkout -b testBranch2 origin/branch
Checkout another branch off the origin/master.
Display all the branches you have, and tells you which branch you are with currently.
git checkout testBranch
Switch to testBranch.
git add index.html
This will add the file index.html for commit
git commmit -m “a test commit”
This will commit the index.html to the your local git repository,
only to the branch you currently at.
A git branch is like a repository itself.
git push origin testBranch:testBranch
This pushes the local testBranch to the remote git repository, it will create the branch testBranch if it doesn’t already exist, otherwise will upload the changes.
So far, we cloned a repository from a remote git server, the clone itself is the master branch. We also created 2 branches off the remote origin/master, testBranch and testBranch2. Then we switch the working copy to testBranch, made some modifications to index.html, committed the change and pushed this branch to the remote server to create a new branch on the remote server.
git checkout master
Now if we switch back to master with this command, the modification we made to the index.html in testBranch will not be there even though we made the changes to the file on the same file directory. We will see the changes again if we switched back to testBranch.
With Git, we can clone a repository and create as many branches as we want wihtin the same file directory. For example, if we clone a repository to /home/myProject/, we can create as many git branches within this same directory and switch between branches. Changes made to one branch will only apply to that branch alone. In another word, we can work in the same file directory with many different branches/projects, we can work on one branch for project A and then do a git checkout to switch to another branch to work on project B.
Search within Codexpedia
Search the entire web