0% found this document useful (0 votes)
5 views

Git Quickreference

The document provides a step-by-step cheatsheet for using Git locally and collaboratively. It outlines setting up Git locally, pulling changes from the master branch, creating and switching to a new feature branch, adding and committing local changes, and pushing the branch to origin to create a merge request.

Uploaded by

gaurav.offerac
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Git Quickreference

The document provides a step-by-step cheatsheet for using Git locally and collaboratively. It outlines setting up Git locally, pulling changes from the master branch, creating and switching to a new feature branch, adding and committing local changes, and pushing the branch to origin to create a merge request.

Uploaded by

gaurav.offerac
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Git cheatsheet (Stepwise)

1. Setup Git locally ( clone server copy to your machine from where you will
perform pull/push)
> git clone <<git-repo-url>>

> git status - tells you the status of your branch


> git branch - this command shows all the branches which you have accessed on
your local PC

2. If you already have git on your PC. Switch to master git branch to sync your
local copy with server copy
> git checkout master

3. Pull content of master to your local (by any 1 command)


> git pull (this will not overwrite any modified file)
> git pull -r ( this will rebase your branch with server content. Overwrite
file with server content)

If pull fails then run stash command to discard any changes you have done
before pull command
> git stash

4. Now create new branch


> git checkout -b feature/<<branch name>>

- you may choose not to use feature/


- -b commands git to create feature branch if not present and switch to it.
If -b is not present means you simply want to switch to your branch

5. Once you have create branch. Create new file in git folder location or modify
any existing file. After you are done making changes. Add those files to you branch
( this will not push your changes to git)
> git status ( this will list all the files which has been modified by you
under current selected branch)

> git add . (. means add all the files modified)


> git add <<file_name>> ( add specific files you want to push, you can run
command for each file or , seperate all the files in single command)

6. Now commit you changes to you branch (still files will not be visible to anyone)
> git commit -m "your message against the commit"

7. Now push changes to git (this will save changes to git and will reflect to
anyone who pulls created branch)
> git push origin feature/<<branch name>>

- you may choose not to use feature/ in branch name


- terminal will provide you an http url to create merge request. Copy that
link and open in browser.

You might also like