Now we are ready to
use Git Bash after much anticipation :p
Go to your project
folder
Right click on the background → Git Bash Here
A command line interface will open for you. As this your first time using Git Bash, you need to do some configurations. Let’s start.
Type git config --global
user.name “yourName”
Next type git
config --global user.email “yourEmailAddress”
Wonder why you did
this?? Okay here is the reason!
When you do commits
in git, they are being tracked with the above details 😊
So now you’re in
your project folder, which you need to upload to your GitHub account
Let’s begin the
real journey!
1. init
git init
1. init
git init
Initialize a git repo in your working directory, note that the current project folder
becomes "master" by default.
Go to your project
folder, you will see a newly created
.git folder (a hidden folder though)
All the version
control stuff will be stored here.
2. status
git status
Reveals the current status of the files in the directory, whether the files have been staged, not tracked or modified.
git status
Reveals the current status of the files in the directory, whether the files have been staged, not tracked or modified.
If you’re executing this command for the very first time all your files will be listed in red colour, indicating that they are untracked
This command can be used at any time without any restrictions
3. add
3. add
git add .
Adds all the files in your folder, to the staging area
Else if you wanna
specify a file, you can use, git add fileName
To remove a file from the staging area (if you think it is not needed to be committed 😉) you can type, git rm --cached fileName
4. commit
git commit –m “yourMessage”
To remove a file from the staging area (if you think it is not needed to be committed 😉)
4. commit
git commit –m “yourMessage”
yourMessage should be a name that helps to
distinguish a commit from the rest.
Remember whenever
you need to do a commit you must first add ’em all to the staging area,
otherwise it will fail (there’s no direct arrow from the working directory to
the local repo)
But there’s a more easy way to do the commit in one step,
But there’s a more easy way to do the commit in one step,
🌟 git commit –a –m “yourMessage”
5. log
git log
List out all the commits for the repo, with the author name and email address.
If you wish to see the commits with only the message you’ve given you can use
git log --oneline
Once your commit
list exceeds your display, it will open up in a command line editor, To skip from the editor hold Shift+zz
6. connect local git to GitHub
Now all that you
need to upload to the remote repository are being committed, but note they are
still in your PC (in the local repository), and no other external parties have
the access yet.
So now it is time
to start using GitHub, you ready??
git remote add nameOfRemoteRepo SSHLink
nameOfRemoteRepo is the name
of the remote repository, you can give any name as you wish, but it’s being
very common to use origin
SSHLink is
the link to your PC to connect to your remote repo.
For that you need
to go back to your GitHub account ➜ select the repo which you wanna upload
the code to,
Use it for the SSHLink
Now your PC knows where the origin is, so all you have to do is upload the code to origin, which is your remote repo,
Now your PC knows where the origin is, so all you have to do is upload the code to origin, which is your remote repo,
7. PUSH
🌟 git push nameOfRemoteRepo nameOfTheBranch
🌟 git push nameOfRemoteRepo nameOfTheBranch
Note: As still you are in your master branch, you need not to worry
about the branch yet
nameOfTheBranch becomes master
nameOfTheBranch becomes master
You’ll be asked for your password, and once it is done, go check your
remote repo (in the GitHub account), you’ll see the files that you’ve uploaded.
So every time you
come up with a change in your project, all you have to do is to type the two commands which I've marked with 🌟 mark, in the Git Bash terminal, to keep your remote repo up to date with your local repo.
Now we are almost done with the basic git commands, but this is not enough for a developer.
No comments:
Post a Comment