DEV Community

Cover image for Getting started with Git and Github
Humza Hasan
Humza Hasan

Posted on • Updated on

Getting started with Git and Github

Steps for working on a new Project from scratch:

Precondition: You have already created a Github repository to commit codes to.

  1. git init (Initialize git repository)
  2. git status (check for untracked and tracked files)
  3. git add . (for all files) or git add {filename}. (for a specific file)
  4. git commit -m “message” (save changes to the local repository)
  5. git remote add origin {remote url} (connecting to Github repository)
  6. git push origin master or git push origin {branchname} (pushing code from local to remote master branch or other named branch)

Note : Please remember not to work on the master branch directly, always create different branches for different purposes. To work on branch use the following command always before adding codes to the staging area:
git checkout -b {branchname}

Steps to start working with other's repository and contributing:

Precondition: Fork the repository in Github which you want to contribute to.

  1. git clone {remoteurl} (Clones your fork repository in local. For first time user)
    or
    git pull {original_repo_url} master (To always pull the latest code from main repository, from second time don't clone but pull)

  2. git checkout -b {branchname} (Change the branch from master to other)

  3. git add . or git add {filename}

  4. git commit -m “message” (save changes to the local repository)

  5. git remote add origin {remote url} (connecting to Github repository)

  6. git push origin {branchname} (pushing code from local to remote branch)

NOTE: Post push request go to Github and create a pull request so that your changes can be added to the main program and be viewed by others too.

Discussion (1)

Collapse
divyakelaskar profile image
Divya Kelaskar

Nice one...
Short & sweet 👍