SAVING YOUR WORKS WITH GIT
Hello Guys, in this write up I’m gonna show you how to upload and save your work on GIT. First lets start by getting GIT installed on our system by visiting the link below to download the GIT setup file
If you’re having any problem installing git on your own, follow this link
(that up there should be enough)…
After you’ve installed GIT on your system, you should have something like this :
You can see that box by right clicking your mouse (The way you’d when you want to refresh your PC without using the f5 key — in windows). You’ll see the Git GUI Here and Git Bash Here options. So you can use git through the command line which is the Git Bash or though the GUI which looks like this
This is how the GIT Bash looks like
LET’S GET STRAIGHT TO WORK
Lets use a demo project I created to learn GIT.
Here a list of GIT Basic commands:
git init —
Initialize a local Git repository
git clone ssh://git@github.com/[username]/[repository-name].git -
Create a local copy of a remote repository
git add [file-name.txt] -
Add a file to the staging area
git add -A -
Add all new and changed files to the staging area
git commit -m "[commit message]"
Commit changes
git rm -r [file-name.txt]
Remove a file (or folder)
git push origin [branch name]
Push a branch to your remote repository
git push -u origin [branch name]
Push changes to remote repository (and remember the branch)
git push
Push changes to remote repository (remembered branch)
git push origin --delete [branch name]
Delete a remote branch
git pull
Update local repository to the newest commit
git pull origin [branch name]
Pull changes from remote repository
git remote add origin ssh://git@github.com/[username]/[repository-name].git
Add a remote repository
git remote set-url origin ssh://git@github.com/[username]/[repository-name].git
Set a repository's origin branch to SSH
git log
View changes
git log --summary
View changes (detailed)
git diff [source branch] [target branch}
Preview changes before merging
Inside your Git Bash, Navigate to any directory using the cd(Change directory) command. Also use the ls command to list sub directories in a particular location. now type ‘cd’ in your Git terminal to go to the home directory, under the ‘Home’ type ‘ls’ to list directories then navigate to your file location using the ‘cd’ command. follow the example in the image below:
After navigating to the particular file you want to use (Now lets start performing the Git magic :)… ), Make sure you are already inside that directory (NOTE: when typing your file name use the Tab key to help you make work easy by auto-completing).
You can use the ‘clear’ command to clear screen(thats by the way), Now lets get to work:
Inside your directory, we need initialize a local git repository(I call it Repo… lol). To initialize a local repo we use the ‘git init’ command.
(Look at this image )
After initializing, lets check the status of our local repo. This can be done by using the ‘git status’ command thus:
Notice its says “No commits yet …” and also a list of three items are coloured red. (Wondering why?) Its because by initializing we only made a request by telling git that “Brother Git! Abeg I want you to help me keep track on some packages” (But we didn’t show this Brother what he’s gonna keep track of ) Thats why its said “ … nothing added to commit but untracked files …”
We need git to keep track of our files and changes made to it(Oh! What are we gonna do? Huh?) Its simple, we just need to use this command: ‘git add . or git add -A (Like saying add all)’. This will tell git that we made changes to our files in the local repo we created earlier and also add all the files to the staging area, now git will be able to keep track of the changes. Look at this:
No lets do the real thing, lets commit(I don’t mean suicide ooo) lets commit our changes, we can achieve this by using the command ‘git commit -m ”message goes here”’( That -m “ ” means you should add a message, like a description). Look at how I did that:
Now you can git status to know your current condition. (Hope you’re getting it?)
HOW TO VIEW COMMIT HISTORY
To view the history of the commits we’ve done. All we need to do is use the command ‘git log or git log — author=”name”
UPLOADING OUR REPO TO GITHUB :)
You can achieve this in two ways:
WAY 1: By signing into github https://github.com then create a new repository. look at this
Click on the create repository button to continue to a page like the one below:
Yippy!!! We’ve successfully created our github repository
But our repo is empty :( Don’t be sad we’re gonna fix that now
You can see on the repo page you get some tips about creating a repo from a command line and …pushing an existing repository from the command line (are you seeing what I am seeing? I hope so)
We only want to push an existing repository from the command line. so copy the http link given to you by github after creating your repo like mine
after copying that go back to your Git Bash inside your existing repo (gan gan) and type in that code except that instead of using my own https link use your own (Again! Abeg use your own oooo)
git remote add origin https://github.com/desmondmuqsit/AndroidIbadan-Chidee.git
Nothing seems to be happening (Huh ?)
Add these line of command
git push -u origin master
Then wait for GIT to perform the magic.
NOTE: TO PUSH, YOU WILL NEED INTERNET CONNECTION… and before doing all these I’d advice you to sign up on github.com if you don’t have a git account.
want master git? follow this tutorial: https://www.youtube.com/watch?v=cEGIFZDyszA&list=PL6gx4Cwl9DGAKWClAD_iKpNC0bGHxGhcx
“ The power of every developer is the ability to use google the right way ” -Chydee:)
This is the end of the CLASS…
“Nobody says it’s gonna be easy you just have to thrive” Quoting Oseni Luthfulahi.
All thanks to OGUNYEIWA SODIQ OPEYEMI, Android Ibadan Developer community for their support and guidance.
#Happy Learning