-----------------------------------------------------------------------------------
WARNING: Technical post
-----------------------------------------------------------------------------------
The whole idea of Git is to have a database for the code edits you have done.
How to install Git for visual studio with screenshots
Main commands of Git
Commit, Push, Pull, Fetch, Remote, Create Branch, Checkout
Branch, Merge, Fork
1- Commit: the commit command is used to commit changes you
have made to files into the local repository (project), when you commit a file,
it means you have copied the changes you made into the local repository (as
shown in figure)
2- Push: the push command allows you to save the changes you
made from the local repository to the remote one, the remote repository is
hosted by several service websites, the most famous is GitHub. (More info on
how to use it with Git: http://help.github.com/create-a-repo/)
3- Fetch: Fetches the project from the remote repository to
the local one (You don’t have to use it)
4- Pull: pulls the projects from the remote repository to
the workspace, but the changes are NOT saved to the local repository.
5- Remote: “remote add” command adds a new remote repository
to the website you have chosen to host your remote repositories. (example: $ git remote add github git@github.com:schacon/hw.git
)
For more on remote commands, check: http://gitref.org/remotes/
“ Branching: Branching
means saving a bookmark of what you currently have, so if you made any changes,
you can switch back to the branch without or with the modifications or
additions.
Example: you are working on the master branch,
then you decided to create a new branch, and switched to it, and started coding
in it, then found that the new piece of code added is working fine, you can
merge the two branches (after switching to the old one), or you found that the
new piece of code isn’t working, you can just remove the branch. I know it
seems complicated but here are 3 photos to illustrate:
Creating new branch
(feature_x)
Merging new branch
(feature_x)
Deleting new branch
(feature_x)
6- Create branch: creates a new branch
7- Branch Checkout: switch into the new branch created
8- Merge branch: merge the two branches together
9- Fork: At some point you may find yourself wanting to
contribute to someone else’s project, or would like to use someone’s project as
the starting point for your own, forking is done on two levels, on your host
website (like Github), you fork the project, and it will be added to your
remote repository, and on your pc, where you run the clone command. When a repo
is cloned, it has a default remote called origin that points to your
fork on GitHub, not the original repo it was forked from. To keep track of the original
repo, you need to add another remote, using remote add command, and then fetch
the forked repository.
Example for a project with the name
Spoon-Knife.git: (from: http://help.github.com/fork-a-repo/)
$ git clone git@github.com:username/Spoon-Knife.git
Clones your copy of the repo into
the current directory in terminal
$ cd
Spoon-Knife
Changes the active directory in
the prompt to the newly cloned "Spoon-Knife" directory
$ git remote
add upstream git://github.com/octocat/Spoon-Knife.git
Assigns the original repo to a
remote called "upstream”
$ git fetch
upstream
Fetches changes
More on Git
Contact me
mohamed.a.e352@gmail.com
No comments:
Post a Comment