GitHub – Repository Handling

Clone a Repository

Let’s see how to clone a project from a existing repository. Let’s think I am a new contributor for my friend’s project. So I am going to clone that project to my new folder. Open your new folder and right click on it. Then click “Git Bash Here“.(First you have to install git bash. If you don’t know what is Git Bash Click here ) This article is for Repository Handling.


Advertisement



In the command prompt, write “git clone your_repo_url“. you can get your repo url from the repository. See the image below.

Get the url from the repository

It will automatically download your repository’s files. That’s it. Now your can open that project.


Pushing files to repository

You already know how to push your file to your repository if you read my previous article. If you don’t know it’s okay. “git push -u origin master” is the command. But you have do somethings before you push. Just think your friend’s repo has many contributors. what happen when they are push their file at the same time. If you have an answer. That’s great. Repository has only final person’s files that is push to the repository. That is why github introduce git branch.


Github – Repository Handling | Check the status and Branching

Just type “git status“. You must do this command after your cloned. You can see what is the branch your are working on it. What is a branch in github?

It’s like a tree. A tree has many branches. In here we can similar a tree to our project. So a project can have many branches. In here we can use a branch to each other. type “git branch“, you can see the all branches in the command prompt.

If you want to create your own branch type “git branch [you_branch_name]“. If you want to switch to another branch and check it out into your working directory, you can use “git checkout” command.


Github – Repository Handling | Git merge

we can use “git merge [branch_name]” to merge. But what is merging? Let’s think my branch is “BuildITMasters_designer”. I did my work in this branch. We have a main branch called “master” and I want to add my work to this branch without changing other’s work. For that we can use this command.

Student Developer pack GitHub (GitHub student pack)Click here to get requirements


Some Git Commands you may need in Version Controlling

  • Git basic Commands
  • git init – will create a new local GIT repository
  • git clone – this is used to copy a repository to your local PC
  • git add – this is used to add a file as it looks now to your next commit.
  • git commit – will create a snapshot of the changes and save it to the git directory
  • git push – push local changes to the original

  • Change files
  • git status – This is used to list new or modified files not yet committed
  • git diff – lists down changes and conflicts
  • git add [FILENAME] – stages the file, this is know as ready for commits
  • git reset [FILENAME] – unstages files, keeping the file changes
  • git commit -m “[MESSAGE]” – commit all stages files to versioned history

  • Branching and merging
  • git branch – will list your branches
  • git checkout -b BRANCH_NAME – create a new branch
  • git merge – will merge the specified branch’s history into the current branch
  • git log – show all commits in the current branch history.

  • Synchronize
  • git fetch – get all changes from the origin without merge
  • git pull – get all the latest changes from the origin and margin
  • git push – is used to upload your local repository changes to the origin remote repository
  • git remote add – create a new connection to a remote repository


Related Git commands and Tutorials.

Thank you for reading. If you are interesting on my article, make sure to follow my other articles as well. Make sure to leave a comment.

guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x