This is a basic step by step process to get started with github and git
1. install git and sign up on github
2. Start by creating a repository which is basically a project
3. on your local machine use git clone <repository_address>
4. Step 3 will download all the files from github in the current location on the local machine
5. Make changes to the file and use git add <filename> to add to local repository
6. Use git commit to commit to the repository
7. Finally use git push to push the current version to github
Use git pull to pull from a repository
Tutorial :http://gitimmersion.com/lab_13.html
Repository is a project
Commit is like a revision of a file. Git every time you save it creates a unique ID (a.k.a. the "SHA" or "hash") that allows you to keep record of what changes were made when and by who
Branch: Branch is a parallel version of repo. the "master" branch is the primary branch which has the live code. When you want to make some change, create a new branch, make changes and merge your branch back with master branch. Merging is done via "pull". which means pulling a branch in another I suppose. To merge your changes with master, you create a "pull request" which is accepted/rejected by repository collaborators.
A fork is a copy of a repository. Fork someonelse repository to for ex createing a patch and send a pull request. If you plan to send a pull request then you also need to keep uptodate with the changes in the original (and not forked) repository. You can setup this by specifiying upstream in your forked repository.
git remote -v gives you the current remote repo.
Add upstream by git remote add upstream https://original-repo-as-upstream
Once you have a fork you can do whatever you want without impacting the opriginal project.
1. You can create a branch and add your changes
2. And send a pull request if you want to merge back.
#Get Add, commit
Once you make changes to file, git knows that the file has changed. (do git status)
but it doesn't know if it should actually recreate hash (which commit does) . So the next step is to "stage" the file for commit by doing git add filename. To commit everything that is staged you do git commit -m "message".
Git only save the changes you made not the entire file. There for if you make some changers to a file, do a git add fname.txt and git commit -m "change1". Followed by more changes., Now the latest (version) commit has only the initial change and not the latest change. You have to stage and commit the new changes.
The commits pile up on the stack as you nake changes to your file, but you can go back anytime by using checkout command. git checkout <hash> takes you to the hash version.
Revert unstaged changes by git checkout <filename>
Revert commited change git revert HEAD (to revert last commit) or git revert <hash> for some othere commit.
HEAD: the current commit your repo is on. Most of the time
Add to commited changes by git commit --ammend -m "some message"
Get changes from remote:
git fetch will fetch the commit from remote branches but will not merge with local branch.
To merge to local git merge origin/master
You can combine these two together by doing git pull
// MEssed up your local dev branch
Deleting:
Locally: git branch -d branch_name
This deletes local branch if it is fully merged with upstream.
git branch -D branch_name
This forcce deltes the branch irrespective of merging.
Its shorthand for git branch --delete --force
To delete remote branch do
git push origin --delete branchname
IF you say git checkout -b <branch> it takes you to the latest version of this branch. git branch --all gives a list of all branches. Current branch is shown with HEAD pointer.
1. install git and sign up on github
2. Start by creating a repository which is basically a project
3. on your local machine use git clone <repository_address>
4. Step 3 will download all the files from github in the current location on the local machine
5. Make changes to the file and use git add <filename> to add to local repository
6. Use git commit to commit to the repository
7. Finally use git push to push the current version to github
Use git pull to pull from a repository
Tutorial :http://gitimmersion.com/lab_13.html
Repository is a project
Commit is like a revision of a file. Git every time you save it creates a unique ID (a.k.a. the "SHA" or "hash") that allows you to keep record of what changes were made when and by who
Branch: Branch is a parallel version of repo. the "master" branch is the primary branch which has the live code. When you want to make some change, create a new branch, make changes and merge your branch back with master branch. Merging is done via "pull". which means pulling a branch in another I suppose. To merge your changes with master, you create a "pull request" which is accepted/rejected by repository collaborators.
A fork is a copy of a repository. Fork someonelse repository to for ex createing a patch and send a pull request. If you plan to send a pull request then you also need to keep uptodate with the changes in the original (and not forked) repository. You can setup this by specifiying upstream in your forked repository.
git remote -v gives you the current remote repo.
Add upstream by git remote add upstream https://original-repo-as-upstream
Once you have a fork you can do whatever you want without impacting the opriginal project.
1. You can create a branch and add your changes
2. And send a pull request if you want to merge back.
#Get Add, commit
Once you make changes to file, git knows that the file has changed. (do git status)
but it doesn't know if it should actually recreate hash (which commit does) . So the next step is to "stage" the file for commit by doing git add filename. To commit everything that is staged you do git commit -m "message".
Git only save the changes you made not the entire file. There for if you make some changers to a file, do a git add fname.txt and git commit -m "change1". Followed by more changes., Now the latest (version) commit has only the initial change and not the latest change. You have to stage and commit the new changes.
The commits pile up on the stack as you nake changes to your file, but you can go back anytime by using checkout command. git checkout <hash> takes you to the hash version.
Revert unstaged changes by git checkout <filename>
Revert commited change git revert HEAD (to revert last commit) or git revert <hash> for some othere commit.
HEAD: the current commit your repo is on. Most of the time
HEAD
points to the latest commit in your branch, but that doesn't have to be the case. HEAD
really just means "what is my repo currently pointing at". In the event that the commit HEAD
refers to is not the tip of any branch, this is called a "detached head"Add to commited changes by git commit --ammend -m "some message"
Branch:
git checkout -b <branchname> is a shortcut for git branch <branchname> followed by a git checkout <branchname>.
Merging:
Merging brings the changes in two branches together. Let’s go back to the greet branch and merge master onto greet. By merging master into your branch periodically, you can pick up any changes to master and keep your changes in greet compatible with changes in the mainline.
git fetch will fetch the commit from remote branches but will not merge with local branch.
To merge to local git merge origin/master
You can combine these two together by doing git pull
// MEssed up your local dev branch
git fetch origin (gets current changes...this is important other wise
you may miss changes)
git reset --hard origin/master
Deleting:
Locally: git branch -d branch_name
This deletes local branch if it is fully merged with upstream.
git branch -D branch_name
This forcce deltes the branch irrespective of merging.
Its shorthand for git branch --delete --force
To delete remote branch do
git push origin --delete branchname
IF you say git checkout -b <branch> it takes you to the latest version of this branch. git branch --all gives a list of all branches. Current branch is shown with HEAD pointer.
.
Master: The name of the default branch that git creates for you when first creating a repo. In most cases, "master" means "the main branch".The default name that git gives to your main remote repo. Your box has its own repo, and you most likely push out to some remote repo that you and all your coworkers push to. That remote repo is almost always called origin, but it doesn't have to be.
git pull = git fetch+git merge
No comments:
Post a Comment